Skip to main content

Getting Started

Building forms in React might be a challenge. We have to face many tedious things like form data, validation, submission, and more 🤯.

As a React developer, there're two strategies for implementing forms, the controlled components and uncontrolled components, each has its advantages and timing of use. The controlled components serve form state as the single source of truth. However, the uncontrolled components make our code more concise and performant.

React Cool Form combines these advantages and references the UX research of Nielsen Norman Group as the basis for our API design to help you conquer all kinds of forms 👊🏻.


To use React Cool Form, you must use react@16.8.0 or greater which includes hooks.


This package is distributed via npm.

$ npm install --save react-cool-form

React Cool Form supports all major browsers. For older browsers (e.g. IE11) without the async/await, Promise, and ES6+ features, you'll need to include a polyfill such as core-js.


If you're not using a module bundler or package manager. We also provide a UMD build which is available over the CDN. Simply use a <script> tag to add it after React CND links as below:

<script crossorigin src=""></script><script crossorigin src=""></script><!-- react-cool-form comes here --><script crossorigin src=""></script>

Then you can access it via the window.ReactCoolForm.<moduleName> variables.


Here's the basic concept of how it rocks:

Edit RCF - Quick start

import { useForm } from "react-cool-form";
const Field = ({ label, id, error, }) => (  <div>    <label htmlFor={id}>{label}</label>    <input id={id} {} />    {error && <p>{error}</p>}  </div>);
const App = () => {  const { form, use } = useForm({    // (Strongly advise) Provide the default values    defaultValues: { username: "", email: "", password: "" },    // The event only triggered when the form is valid    onSubmit: (values) => console.log("onSubmit: ", values),  });  // We can enable the "errorWithTouched" option to filter the error of an un-blurred field  // Which helps the user focus on typing without being annoyed by the error message  const errors = use("errors", { errorWithTouched: true }); // Default is "false"
  return (    <form ref={form} noValidate>      <Field        label="Username"        id="username"        name="username"        // Support built-in validation        required        error={errors.username}      />      <Field        label="Email"        id="email"        name="email"        type="email"        required        error={}      />      <Field        label="Password"        id="password"        name="password"        type="password"        required        minLength={8}        error={errors.password}      />      <input type="submit" />    </form>  );};

✨ Pretty easy right? React Cool Form is more powerful than you think. Let's keep exploring!