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-form-gear

v5.0.1

Published

Simple React Form Validator

Readme

react-form-gear

Simple hook for handling form in simple way fully typed

NPM JavaScript Style Guide

react 18.0 or higher

Install

npm install --save react-form-gear
yarn add react-form-gear

Usage

#define your model with same structure

const LoginFormState = {
  email: {
    value: "",
    isValid: true,
    errorMessage: "",
    constraints: [
      { type: "required", message: "Email is Required" },
      { type: "email", message: "email incorrect" },
    ],
  },
  password: {
    value: "",
    isValid: true,
    errorMessage: "",
    constraints: [
      { type: "required", message: "Password is Required" },
      {
        type: "minLength",
        data: { min: 8 },
        message: "password must be 8 charactor",
      },
    ],
  },
  //Dynamic Function Validation
  zipCode: {
    value: "",
    isValid: true,
    errorMessage: "",
    constraints: [
      { type: "required", message: "zipCode is Required" },
      {
        type: "onlyFourDigit",
        message: "Must four digit",
        validateFunction: {
          onlyFourDigit: (value) => {
            return value.length === 4 ? true : false;
          },
        },
      },
    ],
  },
};
import React from "react";

import useformGear from "react-form-gear";

function App() {
  const { handleChange, handleSubmit, fields, isValidForm, isSubmitting } =
    useformGear({
      formFields: LoginFormState, //use Your Model
      //immediateError: true, --show Error as user start write input
      afterSubmit: (isValid) => {
        //Get is form Valid
        //do after submit valid form
        if (isValid) {
          alert("Form Submit");
        } else {
          alert("Not Valid");
        }
      },
    });

  return (
    <div>
      <h1>React Form Gear</h1>
      <input
        placeholder="email"
        value={fields.email.value}
        onChange={handleChange}
        name={"email"}
      />
      {fields.email.isValid ? null : <h1>{fields.email.errorMessage}</h1>}
      <input
        placeholder="password"
        value={fields.password.value}
        onChange={handleChange} //must
        name={"password"} //must
      />
      {fields.password.isValid ? null : <h1>{fields.password.errorMessage}</h1>}
      <input
        placeholder="Zip Code"
        value={fields.zipCode.value}
        onChange={handleChange} //must
        name={"zipCode"} //must
      />
      {fields.zipCode.isValid ? null : <h1>{fields.zipCode.errorMessage}</h1>}
      <button onClick={handleSubmit}>Submit</button>
    </div>
  );
}
test drive https://codesandbox.io/s/react-form-gear-demo-qr9gu6

With Types

Infer type from given model(But need to follow model structure strictly)

Now fields have fully types

Type of fields from above example is

  const fields: {
    email: {
        value: string;
        isValid: boolean;
        errorMessage: string;
        constraints: {
            type: string;
            message: string;
        }[];
    };
    password: {
        value: string;
        isValid: boolean;
        errorMessage: string;
        constraints: ({
            ...;
        } | {
            ...;
        })[];
    };
} & FormFields

We can infer for you if we can

  useformGear(...)

You can provide generic as args

  useformGear<typeof LoginFormState>

Constraints Types Available

| Types | | :-------- | | required | | email | | minLength | | url | | numbers | | letters | | username |

more will be add

You can add your own validation using dynamic function validation <+> function should return only true or false

 fourDigit: {
    value: "",
    isValid: true,
    errorMessage: "",
    constraints: [
      { type: "required", message: "FourDigit is Required" },
      {
        type: "onlyFourDigit",
        message: "only four digit",
        validateFunction: {//<+>
          onlyFourDigit: value => {
            return value.length == 4 ? true : false;
          }
        }
      }
    ]
  }

Road Map

Typescript Support(Partial Done)

Yup & Zod validator Support

Minor Tweaks

Any Suggestions and improvement are welcome