Package detail

react-cool-form

wellyshen1.4kMIT0.4.1

React hooks for forms state and validation, less code more performant.

react, hooks, form, forms

readme

Hi! friends, if this library has helped you out, please support us with a ⭐️

React Cool Form

React hooks for forms state and validation, less code more performant.

npm version npm downloads coverage status All Contributors netlify deploy

Features

Docs

See the documentation at react-cool-form.netlify.app for more information about using React Cool Form!

Frequently viewed docs:

Quick Start

To use React Cool Form, you must use react@16.8.0 or greater which includes hooks. This package is distributed via npm.

$ yarn add react-cool-form
# or
$ npm install --save react-cool-form

Here's the basic concept of how it rocks:

Edit RCF - Quick start

import { useForm } from "react-cool-form";

const Field = ({ label, id, error, ...rest }) => (
  <div>
    <label htmlFor={id}>{label}</label>
    <input id={id} {...rest} />
    {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={errors.email}
      />
      <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 explore it now!

Articles / Blog Posts

💡 If you have written any blog post or article about React Cool Form, please open a PR to add it here.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Welly

🤔 💻 📖 🚇 🚧

Chris

🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

changelog

react-cool-form

0.4.1

Patch Changes

0.4.0

Minor Changes

0.3.1

Patch Changes

0.3.0

Minor Changes

  • #633 bcb718a Thanks @wellyshen! - Refactor(useForm): turn the shouldValidate parameter of setTouched to object for the purpose of API consistency

0.2.2

Patch Changes

0.2.1

Patch Changes

  • #615 712bb21 Thanks @wellyshen! - Refactor(types): use overloads for the type of useFormState and the field method of useForm

0.2.0

Minor Changes

0.0.171

Patch Changes

  • #572 2401051 Thanks @wellyshen! - Refactor(form-state): reset isSubmitted state when the user attempts to submnit the form

0.0.170

Patch Changes

0.0.169

Patch Changes

0.0.168

Patch Changes

  • 35516ad Thanks @wellyshen! - Fix(useFieldArray): reset values not working for conditional fields

  • c865f58 Thanks @wellyshen! - Refactor: remove "missing field name" warnings

0.0.167

Patch Changes

0.0.166

Patch Changes

  • #562 310cecf Thanks @wellyshen! - Fix(useForm): automatically remove array fields getting wrong form values

0.0.164

Patch Changes

  • #555 546645a Thanks @wellyshen! - Fix(useControlled): value not updated when working with conditional fields and setting default value from defaultValue option

  • #553 6b33570 Thanks @wellyshen! - Fix(useControlled): sync field value with its default value for a conditional field

  • #556 b3edba8 Thanks @wellyshen! - Fix(useControlled): do not update default value when working with field-array

0.0.163

Patch Changes

0.0.162

Patch Changes

0.0.161

Patch Changes

0.0.160

Patch Changes

  • 2a18eca Thanks @wellyshen! - Refactor(useForm): reduce re-rendering times when a field un-mounted

  • 088842d Thanks @wellyshen! - Fix(useFormState): unsubscribe the hook when the component is unmounted

  • 3fb100e Thanks @wellyshen! - Fix(useForm): mon("submitCount") not triggering re-rendering

0.0.159

Patch Changes

  • f457e82 Thanks @wellyshen! - Fix(useControlled): form-level default value might not working with conditional fields

  • b3ec2f7 Thanks @wellyshen! - Refactor(useForm): reduce bundle size

  • b31f0a2 Thanks @wellyshen! - Fix(useForm): should remove form-level default value for conditional fields

  • b2d04e8 Thanks @wellyshen! - Fix(useForm): when multiple mon method are using, only the latest one can work

0.0.158

Patch Changes

  • #536 ed0a7a6 Thanks @wellyshen! - Fix(useForm): when dynamically hidding a field getState method will get default value

0.0.157

Patch Changes

  • #535 7491432 Thanks @wellyshen! - Refactor(useForm): deprecate the shouldFocus parameter of runValidation API

  • 341aa21 Thanks @wellyshen! - Refactor: refine the warning of getting values only

  • 9dc4993 Thanks @wellyshen! - Refactor(useFormState): code refactor for smaller bundle size

0.0.156

Patch Changes

0.0.155

Patch Changes

0.0.154

Patch Changes

0.0.153

Patch Changes

  • 7de1f62 Thanks @wellyshen! - Docs(readme): add arrays-and-lists feature

  • #518 cf7980f Thanks @wellyshen! - Fix(useForm): when running field validation with nested field(s), error results will be overrided by the last field

  • c2459ee Thanks @wellyshen! - Refactor(types): rename Map to ObjMap

0.0.152

Patch Changes

  • 642650c Thanks @wellyshen! - Fix(useFieldArray): avoid touched and dirty values are set at negative index when using push method

0.0.151

Patch Changes

  • d914de6 Thanks @wellyshen! - Fix(useFieldArray): field value not displayed when setting default value via useFieldArray hook

0.0.150

Patch Changes

0.0.149

Patch Changes

  • bfab667 Thanks @wellyshen! - Feat: new on form-state change event mode for useFormState hook

0.0.148

Patch Changes

0.0.147

Patch Changes

0.0.146

Patch Changes

0.0.145

Patch Changes

0.0.144

Patch Changes

  • #487 2d70034 Thanks @wellyshen! - Feat(useFieldArray): better API for fixing the side-effect of React keys and lists

0.0.143

Patch Changes

  • 4f9ae54 Thanks @wellyshen! - Fix(useFieldArray): reset fields not working properly

  • c5a700f Thanks @wellyshen! - Fix(useForm): reserve the default value of field-array from removeField method

0.0.142

Patch Changes

0.0.140

Patch Changes

0.0.139

Patch Changes

0.0.138

Patch Changes

0.0.137

Patch Changes

0.0.136

Patch Changes

0.0.135

Patch Changes

  • c4724a0 Thanks @wellyshen! - Refactor(useForm): skip unnecessary set state logic for reset method

  • 573ab7b #461 Thanks @wellyshen! - Fix(useForm): keep the value of a conditional field when shouldRemoveField option set to false'

  • ae11590 Thanks @wellyshen! - Refactor: refine missing "name" warnings

0.0.134

Patch Changes

  • 742ac71 #451 Thanks @wellyshen! - Fix(useForm): conditional checkbox, radio, and select not working properly

  • cdf5808 Thanks @wellyshen! - Refactor(utils): clear the redundant empty or undefined element(s) of an array

0.0.133

Patch Changes

  • 6dc3cca Thanks @wellyshen! - Fix(useForm): clear the empty element from the array type of form values

0.0.132

Patch Changes

0.0.131

Patch Changes

  • 0e14ea7 #444 Thanks @wellyshen! - Feat: when only on form hook is using, the form id is not required anymore

0.0.130

Patch Changes

  • 723dceb Thanks @wellyshen! - Refactor(useControlled): use React.FocusEventHandler for the return props

0.0.129

Patch Changes

  • 8ae1f76 #436 Thanks @wellyshen! - Fix(useForm): single checkbox input with valid value attribute, the value will be a string array

0.0.128

Patch Changes

0.0.126

Patch Changes

  • fe7942d Thanks @wellyshen! - Fix(useForm): fix potential side-effect of the values of form state

0.0.125

Patch Changes

0.0.124

Patch Changes

  • ed388fb Thanks @wellyshen! - Refactor(useFormState): use error instead warn for form id related exceptions

0.0.123

Patch Changes

0.0.122

Patch Changes

0.0.121

Patch Changes

0.0.120

Patch Changes

  • 090f275 Thanks @wellyshen! - Refactor(useForm): do not unset subscribed state for conditional component

0.0.119

Patch Changes

0.0.118

Patch Changes

  • 1d4e794 #397 Thanks @wellyshen! - Fix(useForm): dirty and isDirty state not work correctly with reference type values

0.0.117

Patch Changes

0.0.116

Patch Changes

0.0.115

Patch Changes

  • 38f64a8 #384 Thanks @wellyshen! - Fix(useForm): prevent errors from calling e.preventDefault() and e.stopPropagation() when using submit or reset methods

0.0.114

Patch Changes

0.0.113

Patch Changes

0.0.112

Patch Changes

0.0.111

Patch Changes

0.0.110

Patch Changes

  • 26284c3 #335 Thanks @wellyshen! - Feat(useForm): change ignoreFields to excludeFields & change data-rcf-ignore to data-rcf-exclude

  • 34b1eb5 Thanks @wellyshen! - Fix(useForm): exclude "button" type from form fields parser

0.0.109

Patch Changes

0.0.108

Patch Changes

0.0.107

Patch Changes

0.0.106

Patch Changes

0.0.105

Patch Changes

0.0.104

Patch Changes

0.0.103

Patch Changes

  • d3c8247 #301 Thanks @wellyshen! - Fix(useForm): pass all parameters back to the onChange handler of the controller API

0.0.102

Patch Changes

0.0.101

Patch Changes

0.0.100

Patch Changes

  • f537695 #288 Thanks @wellyshen! - Fix(useForm): can not clear field(s) due to the side-effect of caching paths

0.0.99

Patch Changes

0.0.98

Patch Changes

0.0.97

Patch Changes

0.0.96

Patch Changes

0.0.95

Patch Changes

0.0.94

Patch Changes

0.0.93

Patch Changes

0.0.92

Patch Changes

0.0.91

Patch Changes

  • 028b95e #265 Thanks @wellyshen! - Perf(useForm): do not trigger re-rendering when imperatively setting the same values

  • f6b97a2 #266 Thanks @wellyshen! - Fix(useForm): update defaultValues by reset(nextValues)

  • 2d25b4a #267 Thanks @wellyshen! - Perf(useForm): do not trigger isValidating when running field-level validation

0.0.90

Patch Changes

0.0.89

Patch Changes

0.0.88

Patch Changes

0.0.87

Patch Changes

0.0.86

Patch Changes

0.0.85

Patch Changes

0.0.84

Patch Changes

0.0.82

Patch Changes

0.0.81

Patch Changes

0.0.80

Patch Changes

0.0.79

Patch Changes

0.0.78

Patch Changes

  • 167fcb6 #232 Thanks @wellyshen! - refactor(useForm): change getState's option name from filterUntouchedErrors to filterUntouchedError

0.0.77

Patch Changes

0.0.76

Patch Changes

0.0.75

Patch Changes

0.0.74

Patch Changes

0.0.72

Patch Changes

0.0.71

Patch Changes

0.0.70

Patch Changes

  • 6dca6ab Thanks @wellyshen! - docs: update getting-started & the API url of README.md & add "API Reference" page

0.0.69

Patch Changes

0.0.68

Patch Changes

0.0.67

Patch Changes

0.0.66

Patch Changes

0.0.65

Patch Changes

0.0.64

Patch Changes

0.0.63

Patch Changes

0.0.62

Patch Changes

0.0.61

Patch Changes

0.0.60

Patch Changes

0.0.59

Patch Changes

0.0.58

Patch Changes

0.0.57

Patch Changes

0.0.56

Patch Changes

0.0.55

Patch Changes

0.0.54

Patch Changes

  • 53fd53c Thanks @wellyshen! - fix(utils): filter the undefined property only for filterError

0.0.53

Patch Changes

0.0.52

Patch Changes

  • fa7ebf6 Thanks @wellyshen! - refactor(utils): delete the filtered property for filterError()

  • 68d232d Thanks @wellyshen! - refactor(useForm): refine the type of controller

0.0.51

Patch Changes

0.0.50

Patch Changes

0.0.49

Patch Changes

0.0.48

Patch Changes

0.0.47

Patch Changes

0.0.46

Patch Changes

0.0.45

Patch Changes

0.0.44

Patch Changes

0.0.43

Patch Changes

  • 6a2939d #155 Thanks @wellyshen! - refactor(useForm): remove iControlFields and excludeFields configs use ignoreFields instead

0.0.42

Patch Changes

0.0.41

Patch Changes

0.0.40

Patch Changes

0.0.39

Patch Changes

0.0.38

Patch Changes

0.0.37

Patch Changes

0.0.36

Patch Changes

0.0.35

Patch Changes

0.0.34

Patch Changes

0.0.33

Patch Changes

0.0.32

Patch Changes

0.0.31

Patch Changes

  • abc5239 Thanks @wellyshen! - refactor(useForm): change runWithLowPrioirty() to requestIdleCallback()

0.0.30

Patch Changes

  • 1621ce1 Thanks @wellyshen! - refactor(useForm): move runWithLowPrioirty into useForm

0.0.29

Patch Changes

0.0.28

Patch Changes

0.0.27

Patch Changes

0.0.26

Patch Changes

0.0.24

Patch Changes

0.0.23

Patch Changes

0.0.22

Patch Changes

  • af29dfd #99 Thanks @wellyshen! - avoid un-necessary re-render & strip hidden input from element checking

  • 4f08865 Thanks @wellyshen! - refactor(useForm): re-parse fields when both add and remove nodes

  • 19e5584 Thanks @wellyshen! - fix(useForm): unset dirtyField if not dirty

0.0.21

Patch Changes

0.0.20

Patch Changes

0.0.19

Patch Changes

0.0.18

Patch Changes

  • 7ec087a #89 Thanks @wellyshen! - refactor(useForm): remove un-necessary for loop from Mutation Observer

0.0.17

Patch Changes

0.0.16

Patch Changes

0.0.15

Patch Changes

0.0.14

Patch Changes

0.0.13

Patch Changes

0.0.12

Patch Changes

0.0.11

Patch Changes

0.0.10

Patch Changes

0.0.9

Patch Changes

  • 0aefe6a #67 Thanks @wellyshen! - feat(useForm): accept function as the values argv of the reset method

  • 8a8f978 #65 Thanks @wellyshen! - refactor(useForm): disabled the watch mode of getFormState() for event & remove un-necessary variable

0.0.8

Patch Changes

0.0.7

Patch Changes

0.0.6

Patch Changes

0.0.5

Patch Changes

0.0.4

Patch Changes

0.0.3

Patch Changes