npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-forms-typescript

v1.0.12

Published

React Form, React Form typescript, React Form Javascript

Downloads

3

Readme

CI

React Form

This library provides an easy way to build forms independent of styling! There is no extra class added to any html element so you might have to apply styling on the native html controls.

Use Cli to create form

If you install this package globally then you can use createForm or using npx! This will start this cli.

I have a created a cli that will allow you to create form and save in your local drive.

Create form

How to use it

npm i react-forms-typescript

or

yarn add react-forms-typescript

Base Components

Following controls are build in for first iteration.

  • TextBox
  • NumberBox
  • Password
  • RadioButton
  • CheckBox
  • SingleFileUplaod
  • MultipleFileUpload
  • MultiLineTextBox
  • SelectBox
  • ValidationError

Validation Components

You can create your own validation components as well

  • Range Validator
  • Regex Validator
  • Required Validator
  • Custom Validator: this will enable you to write any kind of custom validation by providing a simple call back to the validate property of the validator

Utility Components

  • PlainMarkup
  • ShowIf

Extra

Allows you to continue with form completion regardless of internet. It will notify user if there is no internet once internet is back if form is valid it will be submitted automatically!

How it works

The components which are provided as part of react-form framework by default have no validation when form is submitted then all the components which are with in the form there values are provided as FormData which can be passed to backend server for further processing. The moment you add a validation component on top of a normal component it behaves inline with the validation applied.

Following are few examples:

Login Form Example Code snippet


const [payload, setPayload] = React.useState(null)

 const userNameProps: BaseComponentProps = {
   label: "Username",
   name: "user-name",
   id: "user-name",
   placeholder: "Provide Username",
   validationMessage: "Please provide username",
 }

 const passwordProps: BaseComponentProps = {
   label: "Password",
   name: "password",
   id: "password",
   placeholder: "Provide Password",
   validationMessage: "Please provide password",
 }

 const formProps: FormProps = {
   enableOffline: true,
   showValidationSummary: true,
   submitForm: (formData) => {
     fetch(/*api-ul*/, {
       body: formData,
       method: "POST",
     })
       .then((response) => response.json())
       .then(setPayload)
       .catch(console.log)
     console.log("login")
   },
 }
 const requiredValidator1: BaseValidatorProps = { name: "username_required" }
 const requiredValidator2: BaseValidatorProps = { name: "password_required" }

 return (
   <>
     <Form formProps={formProps}>
       <RequiredValidator requiredValidatorProps={requiredValidator1}>
         <TextBox textBoxProps={userNameProps} />
       </RequiredValidator>
       <RequiredValidator requiredValidatorProps={requiredValidator2}>
         <Password passwordProps={passwordProps} />
       </RequiredValidator>
       <div className="button-container">
         <button>Login</button>
       </div>
     </Form>
     {payload && (
       <>
         <h1>Pay load from server :</h1>
         <pre>{JSON.stringify(payload, null, 2)}</pre>
       </>
     )}

Let's try to understand what this is!

  • The snippet is as follows:

| Component | Description | | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | RequiredValidator | This is HOC which will make the username text box mandatory, name is mandatory attribute. | | TextBox | This is the text box component which is provided by the library. You have to pass the textbox props that contains some common properties you have to set like name , id , label and palceholder |


      const userNameProps: BaseComponentProps = {
          label: "Username",
          name: "user-name",
          id: "user-name",
          placeholder: "Provide Username",
          validationMessage: "Please provide username",
        }

        const requiredValidator1: BaseValidatorProps = { name: "username_required" }

        <RequiredValidator requiredValidatorProps={requiredValidator1}>
          <TextBox textBoxProps={userNameProps} />
        </RequiredValidator>

  • The important snippet which we need to understand is

const formProps: FormProps = {
    showValidationSummary: true,
    submitForm: (formData:FormData) => {
      fetch(/*api-ul*/, {
        body: formData,
        method: "POST",
      })
        .then((response) => response.json())
        .then(setPayload)
        .catch(console.log)
      console.log("login")
    },
  }

 <Form formProps={formProps}>
.....
</Form>

There are few properties on FormProps we need to understand

| PropertyName | Description | | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | showValidationSummary | This property will display the validation message summary at the top of the form | | submitForm | This is the callback which executes when user submits form, it has only one parameter which is of FormData type. You can simply send this to your backend server. |

Complete Example

import * as React from "react";
import { render } from "react-dom";

import {
  Form,
  TextBox,
  RequiredValidator,
  Password,
} from "react-form-typescript";

const App = () => {
  const formProps = {
    heading: "Login Form",
    showValidationSummary: true,
    submitForm: (formData) => {
      console.log("login");
    },
  };
  const userNameProps = {
    label: "Username",
    name: "user-name",
    id: "user-name",
    placeholder: "Provide Username",
    validationMessage: "Username is required!",
  };
  const userNameRequiredValidator = { name: "userNameRequiredValidator" };

  const passwordProps = {
    label: "Password :",
    name: "password",
    id: "password",
    placeholder: "Provide password",
    validationMessage: "Password is required!",
  };
  const passwordRequiredValidator = { name: "passwordRequiredValidator" };

  return (
    <Form formProps={formProps}>
      <RequiredValidator requiredValidatorProps={userNameRequiredValidator}>
        <TextBox textBoxProps={userNameProps} />
      </RequiredValidator>

      <RequiredValidator requiredValidatorProps={passwordRequiredValidator}>
        <Password passwordProps={passwordProps} />
      </RequiredValidator>

      <div className="button-container">
        <input type="submit" />
      </div>
    </Form>
  );
};

render(<App />, document.getElementById("app"));

Conditional rendering example

You can use ShowIf component for this purpose. See below a very simple example.


 const formProps: FormProps = {
      submitForm: (data) => {},
      pubsub: new PubSub(),
    };
    const showIfProps: ShowIfProps = {
      id: 'dummy_show_if',
      eventName: 'hello',
      showIfCallback: (data) => false,
    };

    const { getByText, getById, triggerEvent } = render(
      <Form formProps={formProps}>
        <ShowIf showIfProps={showIfProps}>
          <div>this is a test</div>
        </ShowIf>
        <div>
          <button
            id="btn"
            onClick={(e) => {
              formProps.pubsub.publish('hello', null);
            }}
          >
            Click
          </button>
        </div>
      </Form>
    );

Show If component uses a PubSub model.