Repository: wellyshen/react-cool-form
Branch: master
Commit: 24de7b80ee48
Files: 271
Total size: 548.3 KB
Directory structure:
gitextract_9m26ufpr/
├── .all-contributorsrc
├── .changeset/
│ ├── README.md
│ └── config.json
├── .eslintignore
├── .eslintrc.js
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ ├── feature_request.md
│ │ └── question.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── dependabot.yml
│ └── workflows/
│ ├── codeql-analysis.yml
│ ├── release.yml
│ ├── size.yml
│ └── tests.yml
├── .gitignore
├── .husky/
│ ├── pre-commit
│ └── pre-push
├── .nvmrc
├── .prettierignore
├── .vscode/
│ ├── launch.json
│ └── settings.json
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── app/
│ ├── .eslintignore
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── .prettierignore
│ ├── .stylelintrc.js
│ ├── README.md
│ ├── package.json
│ ├── public/
│ │ ├── index.html
│ │ ├── manifest.json
│ │ └── robots.txt
│ ├── src/
│ │ ├── App/
│ │ │ ├── index.tsx
│ │ │ └── styles.ts
│ │ ├── Automation/
│ │ │ └── index.tsx
│ │ ├── Playground/
│ │ │ └── index.tsx
│ │ ├── index.tsx
│ │ ├── react-app-env.d.ts
│ │ └── types/
│ │ └── index.d.ts
│ └── tsconfig.json
├── babel.config.json
├── bundlesize.config.json
├── docs/
│ ├── api-reference/
│ │ ├── use-controlled.md
│ │ ├── use-field-array.md
│ │ ├── use-form-methods.md
│ │ ├── use-form-state.md
│ │ ├── use-form.md
│ │ └── utility-functions.md
│ ├── examples/
│ │ ├── arrays-and-lists.md
│ │ ├── basic.md
│ │ ├── built-in-validation.md
│ │ ├── checkboxes.md
│ │ ├── complex-strcutures.md
│ │ ├── conditional-fields.md
│ │ ├── custom-field.md
│ │ ├── field-level-validation.md
│ │ ├── form-level-validation.md
│ │ ├── form-submission.md
│ │ ├── isolating-rerendering.md
│ │ ├── lazy-default-values.md
│ │ ├── material-ui.md
│ │ ├── multi-select.md
│ │ ├── radio-group.md
│ │ ├── react-select.md
│ │ ├── reset-form.md
│ │ ├── validation-with-schema.md
│ │ ├── virtualized-lists.md
│ │ ├── without-form-element.md
│ │ └── wizard-form.md
│ └── getting-started/
│ ├── 3rd-party-ui-libraries.md
│ ├── accessibility.md
│ ├── arrays-and-lists.md
│ ├── bundle-size-overview.md
│ ├── complex-structures.md
│ ├── form-state.md
│ ├── form-submission.md
│ ├── getting-started.md
│ ├── integration-an-existing-form.md
│ ├── reset-form.md
│ ├── typescript-support.md
│ └── validation-guide.md
├── examples/
│ ├── README.md
│ ├── arrays-and-lists/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── basic/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── built-in-validation/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── checkboxes/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── complex-structures/
│ │ ├── .codesandbox/
│ │ │ └── workspace.json
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── conditional-fields/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── custom-field/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── field-level-validation/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── form-level-validation/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── form-submission/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── isolating-rerendering/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── joi/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── lazy-default-values/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── material-ui/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── multi-select/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── quick-start/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── radio-group/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── react-select/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── reset-form/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── showbox/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── typescript/
│ │ ├── index.tsx
│ │ ├── package.json
│ │ └── styles.scss
│ ├── without-form-element/
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ ├── wizard-form/
│ │ ├── .codesandbox/
│ │ │ └── workspace.json
│ │ ├── Step1.js
│ │ ├── Step2.js
│ │ ├── Step3.js
│ │ ├── formValues.js
│ │ ├── index.js
│ │ ├── package.json
│ │ └── styles.scss
│ └── yup/
│ ├── index.js
│ ├── package.json
│ └── styles.scss
├── package.json
├── scripts/
│ ├── jest/
│ │ ├── config.js
│ │ └── setup.ts
│ └── rollup/
│ ├── cjsEntryFile.js
│ ├── config.js
│ └── createConfig.js
├── src/
│ ├── hooks/
│ │ ├── index.ts
│ │ ├── useLatest.test.ts
│ │ ├── useLatest.ts
│ │ ├── useState.test.ts
│ │ └── useState.ts
│ ├── index.ts
│ ├── shared.test.ts
│ ├── shared.ts
│ ├── types/
│ │ ├── global.d.ts
│ │ ├── index.ts
│ │ └── react-cool-form.d.ts
│ ├── useControlled.test.tsx
│ ├── useControlled.ts
│ ├── useFieldArray.test.tsx
│ ├── useFieldArray.ts
│ ├── useForm.test.tsx
│ ├── useForm.ts
│ ├── useFormMethods.test.tsx
│ ├── useFormMethods.ts
│ ├── useFormState.test.tsx
│ ├── useFormState.ts
│ └── utils/
│ ├── arrayToMap.test.ts
│ ├── arrayToMap.ts
│ ├── cloneObject.test.ts
│ ├── cloneObject.ts
│ ├── compact.test.ts
│ ├── compact.ts
│ ├── deepMerge.test.ts
│ ├── deepMerge.ts
│ ├── filterErrors.test.ts
│ ├── filterErrors.ts
│ ├── get.test.ts
│ ├── get.ts
│ ├── getIsDirty.test.ts
│ ├── getIsDirty.ts
│ ├── getPath.test.ts
│ ├── getPath.ts
│ ├── index.ts
│ ├── invariant.test.ts
│ ├── invariant.ts
│ ├── isAsyncFunction.test.ts
│ ├── isAsyncFunction.ts
│ ├── isCheckboxInput.test.ts
│ ├── isCheckboxInput.ts
│ ├── isEmptyObject.test.ts
│ ├── isEmptyObject.ts
│ ├── isFieldArray.test.ts
│ ├── isFieldArray.ts
│ ├── isFieldElement.test.ts
│ ├── isFieldElement.ts
│ ├── isFileInput.test.ts
│ ├── isFileInput.ts
│ ├── isFileList.ts
│ ├── isFunction.test.ts
│ ├── isFunction.ts
│ ├── isInputElement.test.ts
│ ├── isInputElement.ts
│ ├── isNumberInput.test.ts
│ ├── isNumberInput.ts
│ ├── isObject.test.ts
│ ├── isObject.ts
│ ├── isPlainObject.test.ts
│ ├── isPlainObject.ts
│ ├── isRadioInput.test.ts
│ ├── isRadioInput.ts
│ ├── isRangeInput.test.ts
│ ├── isRangeInput.ts
│ ├── isSelectMultiple.test.ts
│ ├── isSelectMultiple.ts
│ ├── isSelectOne.test.ts
│ ├── isSelectOne.ts
│ ├── isUndefined.test.ts
│ ├── isUndefined.ts
│ ├── parseState.test.ts
│ ├── parseState.ts
│ ├── runWithLowPriority.test.ts
│ ├── runWithLowPriority.ts
│ ├── set.test.ts
│ ├── set.ts
│ ├── setValuesAsTrue.test.ts
│ ├── setValuesAsTrue.ts
│ ├── stringToPath.test.ts
│ ├── stringToPath.ts
│ ├── unset.test.ts
│ ├── unset.ts
│ ├── warn.test.ts
│ └── warn.ts
├── tsconfig.json
└── website/
├── .gitignore
├── .prettierignore
├── README.md
├── babel.config.js
├── docusaurus.config.js
├── package.json
├── sidebars.js
├── src/
│ ├── css/
│ │ └── custom.scss
│ └── pages/
│ ├── index.js
│ └── styles.module.scss
└── static/
└── .nojekyll
================================================
FILE CONTENTS
================================================
================================================
FILE: .all-contributorsrc
================================================
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "wellyshen",
"name": "Welly",
"avatar_url": "https://avatars.githubusercontent.com/u/21308003?v=4",
"profile": "http://wellyshen.com",
"contributions": [
"ideas",
"code",
"doc",
"infra",
"maintenance"
]
},
{
"login": "Chris-James",
"name": "Chris",
"avatar_url": "https://avatars.githubusercontent.com/u/4596428?v=4",
"profile": "https://github.com/Chris-James",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,
"projectName": "react-cool-form",
"projectOwner": "wellyshen",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}
================================================
FILE: .changeset/README.md
================================================
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/master/docs/common-questions.md)
================================================
FILE: .changeset/config.json
================================================
{
"$schema": "https://unpkg.com/@changesets/config@1.7.0/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "wellyshen/react-cool-form" }
],
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
================================================
FILE: .eslintignore
================================================
dist
scripts/rollup
app
examples
website
================================================
FILE: .eslintrc.js
================================================
module.exports = {
extends: ["welly"],
rules: {
eqeqeq: "off",
camelcase: "off",
"no-shadow": "off",
"no-console": [
"warn",
{
allow: ["warn", "error"],
},
],
"no-param-reassign": "off",
"no-underscore-dangle": "off",
"no-sparse-arrays": "off",
"no-restricted-syntax": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"testing-library/render-result-naming-convention": "off",
},
settings: {
polyfills: ["Promise"],
},
};
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: react-cool-form
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: "\U0001F41B Bug Report"
about: Create a report to help us improve
title: ""
labels: ""
assignees: ""
---
# Bug Report
## Describe the Bug
A clear and concise description of what the bug is.
## How to Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
1. Go to '....'
2. Click on '....'
3. See error
## CodeSandbox Link
Show me the bug on [CodeSandbox](https://codesandbox.io).
## Expected Behavior
Tell me what should happen.
## Screenshots
Add screenshots to help explain your problem.
## Your Environment
- Device: [e.g. MacBook Pro, iPhone12]
- OS: [e.g. macOS, iOS, Windows]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. v1.0.0]
## Additional Information
Any other information about the problem here.
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: "\U0001F4A1 Feature Request"
about: Suggest an idea for this project
title: ""
labels: ""
assignees: ""
---
# Feature Request
## Describe the Feature
A clear and concise description of what you want and what your use case is.
## Describe the Solution You'd Like
A clear and concise description of what you want to happen.
## Describe Alternatives You've Considered
A clear and concise description of any alternative solutions or features you've considered.
## Additional Information
Any other information about the feature here.
================================================
FILE: .github/ISSUE_TEMPLATE/question.md
================================================
---
name: "\U0001F914 Questions and Help"
about: This issue tracker is not for questions. Please ask questions at https://stackoverflow.com/questions/tagged/react.
title: ""
labels: ""
assignees: ""
---
GitHub Issues are reserved for Bug reports and Feature requests. Support requests that are created as issues are likely to be closed. We want to make sure you are able to find the help you seek. Please take a look at the following resources.
## Coding Questions
If you have a coding question related to React, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.
https://stackoverflow.com/questions/tagged/react
## Support Forums
There are many online forums which are a great place for discussion about best practices and application architecture.
https://reactjs.org/community/support.html#popular-discussion-forums
================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
## What
What changes are being made? (e.g. feature, bug, docs, etc.)
## Why
Why are these changes necessary?
## How
How were these changes implemented?
## Checklist
Have you done all of these things?
- [ ] [Documentation](https://github.com/wellyshen/react-cool-form/tree/master/docs) added
- [ ] Tests
- [ ] TypeScript definitions updated
- [ ] [Add a changeset](https://github.com/atlassian/changesets/blob/master/docs/adding-a-changeset.md)
- [ ] Ready to be merged
================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "21:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: "@changesets/changelog-github"
versions:
- 0.3.0
- 0.4.0
- dependency-name: "@rollup/plugin-commonjs"
versions:
- 18.0.0
- dependency-name: husky
versions:
- 5.0.9
- 5.1.1
- 6.0.0
- dependency-name: rollup
versions:
- 2.40.0
- 2.42.4
- dependency-name: "@testing-library/user-event"
versions:
- 13.0.0
- 13.0.1
- 13.0.2
- 13.0.3
- 13.0.6
- 13.0.7
================================================
FILE: .github/workflows/codeql-analysis.yml
================================================
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: "40 18 * * 1"
jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
# Override language selection by uncommenting this and choosing your languages
with:
languages: javascript
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
================================================
FILE: .github/workflows/release.yml
================================================
name: Release
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install Dependencies
run: yarn
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
================================================
FILE: .github/workflows/size.yml
================================================
name: Compressed Size
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: preactjs/compressed-size-action@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
build-script: "build:prod"
================================================
FILE: .github/workflows/tests.yml
================================================
name: Lint / Test / Size
on:
push:
branches:
- master
tags-ignore:
- "**"
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run lint
run: yarn lint
- name: Run test
run: yarn test:cov
- name: Run size limit
run: yarn size
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
================================================
FILE: .gitignore
================================================
# dependencies
node_modules
# testing
coverage
# production
dist
# misc
.size-snapshot.json
.DS_Store
*.log
================================================
FILE: .husky/pre-commit
================================================
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint-staged
================================================
FILE: .husky/pre-push
================================================
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn test
yarn size
================================================
FILE: .nvmrc
================================================
lts/*
================================================
FILE: .prettierignore
================================================
dist
coverage
app
examples
website
*.log
.size-snapshot.json
================================================
FILE: .vscode/launch.json
================================================
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
================================================
FILE: .vscode/settings.json
================================================
{
"typescript.tsdk": "node_modules/typescript/lib"
}
================================================
FILE: CHANGELOG.md
================================================
# react-cool-form
## 0.4.1
### Patch Changes
- [#697](https://github.com/wellyshen/react-cool-form/pull/697) [`87eb83e`](https://github.com/wellyshen/react-cool-form/commit/87eb83e32aa11c0ddc6d87e3b5ba1e53886ed622) Thanks [@wellyshen](https://github.com/wellyshen)! - fix: `reset` method not working
## 0.4.0
### Minor Changes
- [#654](https://github.com/wellyshen/react-cool-form/pull/654) [`291199a`](https://github.com/wellyshen/react-cool-form/commit/291199a021e6ae81af5bb5b79b77ac1f27f8b511) Thanks [@wellyshen](https://github.com/wellyshen)! - feat(useForm): add `shouldFocus` option for `runValidation` method
## 0.3.1
### Patch Changes
- [#640](https://github.com/wellyshen/react-cool-form/pull/640) [`61e1d53`](https://github.com/wellyshen/react-cool-form/commit/61e1d533e3d51fff33cbd91997adf280167fb7fc) Thanks [@wellyshen](https://github.com/wellyshen)! - refactor(types): use `RefObject` as the type of `form` method
## 0.3.0
### Minor Changes
- [#633](https://github.com/wellyshen/react-cool-form/pull/633) [`bcb718a`](https://github.com/wellyshen/react-cool-form/commit/bcb718add9b21c49e6832b037e0e913d9c096c6c) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): turn the `shouldValidate` parameter of `setTouched` to object for the purpose of API consistency
## 0.2.2
### Patch Changes
- [#619](https://github.com/wellyshen/react-cool-form/pull/619) [`8807efd`](https://github.com/wellyshen/react-cool-form/commit/8807efd0a3fea05e870c10a4ea22546f5f85a1fc) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(types): export more types
## 0.2.1
### Patch Changes
- [#615](https://github.com/wellyshen/react-cool-form/pull/615) [`712bb21`](https://github.com/wellyshen/react-cool-form/commit/712bb21736bdc5990c38e1f822812f2b20081bea) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(types): use overloads for the type of `useFormState` and the `field` method of `useForm`
## 0.2.0
### Minor Changes
- [#610](https://github.com/wellyshen/react-cool-form/pull/610) [`072da4b`](https://github.com/wellyshen/react-cool-form/commit/072da4b842d741e022ba2125528095e624c0f3d4) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): rename `mon` to `use`
## 0.0.171
### Patch Changes
- [#572](https://github.com/wellyshen/react-cool-form/pull/572) [`2401051`](https://github.com/wellyshen/react-cool-form/commit/2401051c8128ffd8a17468bd8ec1f9ed0bf5b281) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(form-state): reset `isSubmitted` state when the user attempts to submnit the form
## 0.0.170
### Patch Changes
- [#570](https://github.com/wellyshen/react-cool-form/pull/570) [`21bac87`](https://github.com/wellyshen/react-cool-form/commit/21bac870b3063a6f6c8ee976d07a6b07e2192bd9) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): rename `debug` event to `onStateChange`
## 0.0.169
### Patch Changes
- [#568](https://github.com/wellyshen/react-cool-form/pull/568) [`d6bcac6`](https://github.com/wellyshen/react-cool-form/commit/d6bcac62266057f71bac0ceedaf731f3a62aea70) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): new `removeOnUnmounted` option
## 0.0.168
### Patch Changes
- [`35516ad`](https://github.com/wellyshen/react-cool-form/commit/35516ad867efb6d1314a2580af360f9143423775) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): reset values not working for conditional fields
* [`c865f58`](https://github.com/wellyshen/react-cool-form/commit/c865f58504e416ccd55b4b2022f3092c1c841c80) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: remove "missing field name" warnings
## 0.0.167
### Patch Changes
- [#565](https://github.com/wellyshen/react-cool-form/pull/565) [`f1796dd`](https://github.com/wellyshen/react-cool-form/commit/f1796dd459f641544f0365ff6e4d331f8d5c45d7) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): reset form will cause `undefined` form values
## 0.0.166
### Patch Changes
- [#562](https://github.com/wellyshen/react-cool-form/pull/562) [`310cecf`](https://github.com/wellyshen/react-cool-form/commit/310cecf66a658c615f38e3b243c0491321189ffc) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): automatically remove array fields getting wrong form values
## 0.0.164
### Patch Changes
- [#555](https://github.com/wellyshen/react-cool-form/pull/555) [`546645a`](https://github.com/wellyshen/react-cool-form/commit/546645a9945092582237e47c28040e54716a7821) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useControlled): value not updated when working with conditional fields and setting default value from `defaultValue` option
* [#553](https://github.com/wellyshen/react-cool-form/pull/553) [`6b33570`](https://github.com/wellyshen/react-cool-form/commit/6b33570e999ccd8e445aa227dbea386f3e3ec0d8) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useControlled): sync field value with its default value for a conditional field
- [#556](https://github.com/wellyshen/react-cool-form/pull/556) [`b3edba8`](https://github.com/wellyshen/react-cool-form/commit/b3edba847372e8a7baf556bf78c71c1d25eba738) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useControlled): do not update default value when working with field-array
## 0.0.163
### Patch Changes
- [#551](https://github.com/wellyshen/react-cool-form/pull/551) [`e285de3`](https://github.com/wellyshen/react-cool-form/commit/e285de3f1e3d96cda611d4cd0b6992ae49c74dcb) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: reduce bundle size
## 0.0.162
### Patch Changes
- [#549](https://github.com/wellyshen/react-cool-form/pull/549) [`b1cfeae`](https://github.com/wellyshen/react-cool-form/commit/b1cfeaea9d43d037d467789ff9c9db45e8cd6724) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): new `removeField` API
## 0.0.161
### Patch Changes
- [#542](https://github.com/wellyshen/react-cool-form/pull/542) [`2e008df`](https://github.com/wellyshen/react-cool-form/commit/2e008dfc3cd933249eebe3d1c9e8f5203383e3e6) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: reduce bundle size
## 0.0.160
### Patch Changes
- [`2a18eca`](https://github.com/wellyshen/react-cool-form/commit/2a18eca80cf9ed0ec6c2cd9d6c479c0ea1c52449) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): reduce re-rendering times when a field un-mounted
* [`088842d`](https://github.com/wellyshen/react-cool-form/commit/088842d2d825893b3246d9d381ef2b7b7071a04c) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFormState): unsubscribe the hook when the component is unmounted
- [`3fb100e`](https://github.com/wellyshen/react-cool-form/commit/3fb100e263cae996acc28e87d611434f5a862836) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): `mon("submitCount")` not triggering re-rendering
## 0.0.159
### Patch Changes
- [`f457e82`](https://github.com/wellyshen/react-cool-form/commit/f457e829256e85400212fddf3d3697cfbd3541f8) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useControlled): form-level default value might not working with conditional fields
* [`b3ec2f7`](https://github.com/wellyshen/react-cool-form/commit/b3ec2f7c105b53922ded53d84deffd8d0eaf012b) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): reduce bundle size
- [`b31f0a2`](https://github.com/wellyshen/react-cool-form/commit/b31f0a2a3b18f0cd8c51e761379a62f02935e464) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): should remove form-level default value for conditional fields
* [`b2d04e8`](https://github.com/wellyshen/react-cool-form/commit/b2d04e89197d0b38b255f06b9274a90025239014) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): when multiple `mon` method are using, only the latest one can work
## 0.0.158
### Patch Changes
- [#536](https://github.com/wellyshen/react-cool-form/pull/536) [`ed0a7a6`](https://github.com/wellyshen/react-cool-form/commit/ed0a7a62cb9437a29e05012f1806a74f0f3f3e63) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): when dynamically hidding a field `getState` method will get default value
## 0.0.157
### Patch Changes
- [#535](https://github.com/wellyshen/react-cool-form/pull/535) [`7491432`](https://github.com/wellyshen/react-cool-form/commit/749143284089fe956efbaab9de2d3869dabd4430) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): deprecate the `shouldFocus` parameter of `runValidation` API
* [`341aa21`](https://github.com/wellyshen/react-cool-form/commit/341aa214d02dd7de8834827b4c3158d7e1acefb8) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: refine the warning of getting `values` only
- [`9dc4993`](https://github.com/wellyshen/react-cool-form/commit/9dc4993824083c9086927281135fb9265fd3936e) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useFormState): code refactor for smaller bundle size
## 0.0.156
### Patch Changes
- [#530](https://github.com/wellyshen/react-cool-form/pull/530) [`62762d0`](https://github.com/wellyshen/react-cool-form/commit/62762d09701265ac5e8c68ffaade17dd37295e63) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFormState): `errorWithTouched` option not works in some cases
* [#529](https://github.com/wellyshen/react-cool-form/pull/529) [`dc35110`](https://github.com/wellyshen/react-cool-form/commit/dc35110c7f93aa09d3d7cbaf672282a29c21699f) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): add `shouldFocus` for `runValidation` API
- [#532](https://github.com/wellyshen/react-cool-form/pull/532) [`4c6fe9e`](https://github.com/wellyshen/react-cool-form/commit/4c6fe9ece87304ab2baa0db627176e7060f9e685) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): do not warn missing name when excluding a field via data attribute
## 0.0.155
### Patch Changes
- [#527](https://github.com/wellyshen/react-cool-form/pull/527) [`10af065`](https://github.com/wellyshen/react-cool-form/commit/10af065a4ce4de597fbce2a5f68923f68c330021) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): delay = 0 is acceptable by `focus` method
## 0.0.154
### Patch Changes
- [#519](https://github.com/wellyshen/react-cool-form/pull/519) [`5539448`](https://github.com/wellyshen/react-cool-form/commit/5539448c8c7ee1fedd19d12cb79d909fcf781fa4) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): new `setFocus` API
* [`06e66f3`](https://github.com/wellyshen/react-cool-form/commit/06e66f38de31ebf335dd04543a5a118e1202d18a) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): when working with nested fields, built-in validation results are overrided
## 0.0.153
### Patch Changes
- [`7de1f62`](https://github.com/wellyshen/react-cool-form/commit/7de1f62fb3b03d1aef8a5fe7041fedf1a48931fe) Thanks [@wellyshen](https://github.com/wellyshen)! - Docs(readme): add arrays-and-lists feature
* [#518](https://github.com/wellyshen/react-cool-form/pull/518) [`cf7980f`](https://github.com/wellyshen/react-cool-form/commit/cf7980f72790bc6f5a95192fff629ec909ab38ad) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): when running field validation with nested field(s), error results will be overrided by the last field
- [`c2459ee`](https://github.com/wellyshen/react-cool-form/commit/c2459eebbd18fd2cdbf58aa3552d51cbc650c5c0) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(types): rename `Map` to `ObjMap`
## 0.0.152
### Patch Changes
- [`642650c`](https://github.com/wellyshen/react-cool-form/commit/642650c610893f65a83cd384a06bff1d82b5f4ba) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): avoid touched and dirty values are set at negative index when using `push` method
## 0.0.151
### Patch Changes
- [`d914de6`](https://github.com/wellyshen/react-cool-form/commit/d914de63a527a5188afd0ba0ea7203dcd9fd17cb) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): field value not displayed when setting default value via `useFieldArray` hook
## 0.0.150
### Patch Changes
- [`98cd462`](https://github.com/wellyshen/react-cool-form/commit/98cd46202296b720dff48352fd90d418596599b4) Thanks [@wellyshen](https://github.com/wellyshen)! - Docs(readme): update features section
* [`cd8755b`](https://github.com/wellyshen/react-cool-form/commit/cd8755b265b6ec592312cb2690f18650ee1919de) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): correct form ID warning message
## 0.0.149
### Patch Changes
- [`bfab667`](https://github.com/wellyshen/react-cool-form/commit/bfab667e915f33ceb974195bf7cc12e10cde4be1) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat: new on form-state change event mode for `useFormState` hook
## 0.0.148
### Patch Changes
- [#499](https://github.com/wellyshen/react-cool-form/pull/499) [`38cfd17`](https://github.com/wellyshen/react-cool-form/commit/38cfd17cd6b79345652a88ede0329ec328674139) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useFieldArray): provide simpler API
## 0.0.147
### Patch Changes
- [#494](https://github.com/wellyshen/react-cool-form/pull/494) [`40e9b76`](https://github.com/wellyshen/react-cool-form/commit/40e9b76e74b2740fd8e6c309353bf9e77127998e) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat: shortcut for getting form's values
* [#492](https://github.com/wellyshen/react-cool-form/pull/492) [`4f0dbaf`](https://github.com/wellyshen/react-cool-form/commit/4f0dbaf6610bad9977b474b92e158c0d83227755) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): throw multiple warning when getting form values with `mon` method
## 0.0.146
### Patch Changes
- [`68b340a`](https://github.com/wellyshen/react-cool-form/commit/68b340a93188b23fd22303e7c097770be7b0cc56) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): correct the type of return values
## 0.0.145
### Patch Changes
- [#489](https://github.com/wellyshen/react-cool-form/pull/489) [`1eee601`](https://github.com/wellyshen/react-cool-form/commit/1eee601ef0b121387e1744290b0c62d62c0c277d) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): fields not updated by helper methods
## 0.0.144
### Patch Changes
- [#487](https://github.com/wellyshen/react-cool-form/pull/487) [`2d70034`](https://github.com/wellyshen/react-cool-form/commit/2d70034f2d4b8c9b4dd11a55eac42e1e19b3e41b) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useFieldArray): better API for fixing the side-effect of React keys and lists
## 0.0.143
### Patch Changes
- [`4f9ae54`](https://github.com/wellyshen/react-cool-form/commit/4f9ae542010d413b1bc466a99b7c479249e39b2e) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): reset fields not working properly
* [`c5a700f`](https://github.com/wellyshen/react-cool-form/commit/c5a700f26004f5c7ec5772eb7578bfd6cff5cee4) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): reserve the default value of field-array from `removeField` method
## 0.0.142
### Patch Changes
- [#481](https://github.com/wellyshen/react-cool-form/pull/481) [`90afddc`](https://github.com/wellyshen/react-cool-form/commit/90afddc7f61d76a891c0451410e383f8906f3c08) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFieldArray): reset not working
* [#484](https://github.com/wellyshen/react-cool-form/pull/484) [`d5d68bc`](https://github.com/wellyshen/react-cool-form/commit/d5d68bcf7500caefc2faa3081bbdb46a6e9242be) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useControlled): controlled components not working with field-array
## 0.0.140
### Patch Changes
- [#474](https://github.com/wellyshen/react-cool-form/pull/474) [`b6f7589`](https://github.com/wellyshen/react-cool-form/commit/b6f758990a59969c947158727a82789087f2566c) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): rename `select` method to `watch` for better understanding
* [#474](https://github.com/wellyshen/react-cool-form/pull/474) [`3cdcd1b`](https://github.com/wellyshen/react-cool-form/commit/3cdcd1bd3a6c2bcdaab69846ac60f9c02ef597cf) Thanks [@wellyshen](https://github.com/wellyshen)! - Change `select` method to `mon` (a.k.a monitor)
- [`2d0ba41`](https://github.com/wellyshen/react-cool-form/commit/2d0ba41c00036ed1526c8d92cff7dcd25cbfd0d7) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): wrong form values due to automatically remove a field
## 0.0.139
### Patch Changes
- [`9bb9992`](https://github.com/wellyshen/react-cool-form/commit/9bb9992c666d52c17ce929d7d273b2fd885766b3) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: refine warning messages
## 0.0.138
### Patch Changes
- [`889e331`](https://github.com/wellyshen/react-cool-form/commit/889e3319d5f064607cef4dec42a3e5fb32cdadb4) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(utils): the side-effect of `cloneObject`
## 0.0.137
### Patch Changes
- [`d808960`](https://github.com/wellyshen/react-cool-form/commit/d80896022c8322dfe4aed5facc57b40874151a82) [#466](https://github.com/wellyshen/react-cool-form/pull/466) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): `isDirty` not working with array type form values
## 0.0.136
### Patch Changes
- [`c066ecc`](https://github.com/wellyshen/react-cool-form/commit/c066ecc5004d6b29d9d649a41f99290d5f52234f) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: reduce bundle size
## 0.0.135
### Patch Changes
- [`c4724a0`](https://github.com/wellyshen/react-cool-form/commit/c4724a04a1d60c767f501bc74f35393e835c31d1) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): skip unnecessary set state logic for `reset` method
* [`573ab7b`](https://github.com/wellyshen/react-cool-form/commit/573ab7b6f29d2a7e9b503bd1cdaf772d903b5952) [#461](https://github.com/wellyshen/react-cool-form/pull/461) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): keep the value of a conditional field when `shouldRemoveField` option set to `false`'
- [`ae11590`](https://github.com/wellyshen/react-cool-form/commit/ae115903890ee8d1b8f8d79d4acb399a375244c6) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: refine missing "name" warnings
## 0.0.134
### Patch Changes
- [`742ac71`](https://github.com/wellyshen/react-cool-form/commit/742ac71d7f2126745c10c044427bd31e2edb5cf0) [#451](https://github.com/wellyshen/react-cool-form/pull/451) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): conditional `checkbox`, `radio`, and `select` not working properly
* [`cdf5808`](https://github.com/wellyshen/react-cool-form/commit/cdf580863bb0b9a096b7f6838040f7dd57f9eb37) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(utils): clear the redundant `empty` or `undefined` element(s) of an array
## 0.0.133
### Patch Changes
- [`6dc3cca`](https://github.com/wellyshen/react-cool-form/commit/6dc3ccaaae66b11e5069084610143f760a387fc1) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): clear the `empty` element from the array type of form values
## 0.0.132
### Patch Changes
- [`91cfe37`](https://github.com/wellyshen/react-cool-form/commit/91cfe37e794a1a6f1d4129c995598964173d39a9) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix: empty array values for `useForm` hook and `set` utility function
* [`ada163b`](https://github.com/wellyshen/react-cool-form/commit/ada163b04922341575a9b979530f31006bfb9203) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(types): enhance the readability of type
- [`d723cf0`](https://github.com/wellyshen/react-cool-form/commit/d723cf058cfab68a0c694b84553422617d2cafab) [#447](https://github.com/wellyshen/react-cool-form/pull/447) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(unset): remove the ancestry path of the unset property if needed
## 0.0.131
### Patch Changes
- [`0e14ea7`](https://github.com/wellyshen/react-cool-form/commit/0e14ea76ea61e7025cc76b84b37c64b9b70d7fdd) [#444](https://github.com/wellyshen/react-cool-form/pull/444) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat: when only on form hook is using, the form id is not required anymore
## 0.0.130
### Patch Changes
- [`723dceb`](https://github.com/wellyshen/react-cool-form/commit/723dcebb8f08fd3393ddcaa06ebf317c700ff337) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useControlled): use React.FocusEventHandler for the return props
## 0.0.129
### Patch Changes
- [`8ae1f76`](https://github.com/wellyshen/react-cool-form/commit/8ae1f76a065a94375e2bf0143f8adcd981a63230) [#436](https://github.com/wellyshen/react-cool-form/pull/436) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): single checkbox input with valid `value` attribute, the value will be a string array
## 0.0.128
### Patch Changes
- [`b3554f2`](https://github.com/wellyshen/react-cool-form/commit/b3554f28ed13e4d89ac437e42d4c370b1431ec09) [#433](https://github.com/wellyshen/react-cool-form/pull/433) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): add `id` and `class` for the `excludeFields` option
## 0.0.126
### Patch Changes
- [`fe7942d`](https://github.com/wellyshen/react-cool-form/commit/fe7942d36ee2410ad3be9dc74318836b850cb6cb) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): fix potential side-effect of the values of form state
## 0.0.125
### Patch Changes
- [`eb767bd`](https://github.com/wellyshen/react-cool-form/commit/eb767bd4758ebbec37efde3975c1eab822d2de6b) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): fix set default values side-effect
## 0.0.124
### Patch Changes
- [`ed388fb`](https://github.com/wellyshen/react-cool-form/commit/ed388fbd2691b91e1335e88bd5238bac36f3a76c) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useFormState): use error instead warn for form id related exceptions
## 0.0.123
### Patch Changes
- [`e7795c3`](https://github.com/wellyshen/react-cool-form/commit/e7795c30c36b26e402d4b07e458ee2f5f2617063) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useFormState): correct the URL of warnings
## 0.0.122
### Patch Changes
- [`3f92f38`](https://github.com/wellyshen/react-cool-form/commit/3f92f3861baa7bfe51e1ba67525055c0ae97f09d) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat: new `useFormState` hook
## 0.0.121
### Patch Changes
- [`cc3eb6c`](https://github.com/wellyshen/react-cool-form/commit/cc3eb6c845ba540de38bc2cab9a708b5bbc6739f) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): add `false` type for form validator
## 0.0.120
### Patch Changes
- [`090f275`](https://github.com/wellyshen/react-cool-form/commit/090f27576174431f948c9a72ff3b8950b93d986c) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): do not unset subscribed state for conditional component
## 0.0.119
### Patch Changes
- [`d4c7258`](https://github.com/wellyshen/react-cool-form/commit/d4c7258382b2aa5e4f2937973e7c5f253caf5a73) [#405](https://github.com/wellyshen/react-cool-form/pull/405) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): should call `debug` on every state changed
* [`b0a5141`](https://github.com/wellyshen/react-cool-form/commit/b0a5141d589d1e82924e5f8b7eb4e8bee02bfbd6) [#403](https://github.com/wellyshen/react-cool-form/pull/403) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor(useForm): do not trigger re-renders on reset if no any selected state
## 0.0.118
### Patch Changes
- [`1d4e794`](https://github.com/wellyshen/react-cool-form/commit/1d4e79401f92ee2f4060efdfa377d769b6ff9a86) [#397](https://github.com/wellyshen/react-cool-form/pull/397) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): `dirty` and `isDirty` state not work correctly with reference type values
## 0.0.117
### Patch Changes
- [`5797ca4`](https://github.com/wellyshen/react-cool-form/commit/5797ca447cb4024dd8f56e9b1e3afc6bef607b60) [#394](https://github.com/wellyshen/react-cool-form/pull/394) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): add "select" method
## 0.0.116
### Patch Changes
- [`645b5f4`](https://github.com/wellyshen/react-cool-form/commit/645b5f4269737f535735e73eea242bb3a48dfff7) [#391](https://github.com/wellyshen/react-cool-form/pull/391) Thanks [@wellyshen](https://github.com/wellyshen)! - Refactor: refine types
## 0.0.115
### Patch Changes
- [`38f64a8`](https://github.com/wellyshen/react-cool-form/commit/38f64a8423dd6b3bb8fe4b61e139312c74e9a113) [#384](https://github.com/wellyshen/react-cool-form/pull/384) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): prevent errors from calling `e.preventDefault()` and `e.stopPropagation()` when using `submit` or `reset` methods
## 0.0.114
### Patch Changes
- [`87f7814`](https://github.com/wellyshen/react-cool-form/commit/87f7814bc6756254658938268d825533ae50c208) [#360](https://github.com/wellyshen/react-cool-form/pull/360) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useState): trigger `debug` callback whenever form state changed
## 0.0.113
### Patch Changes
- [`a90c405`](https://github.com/wellyshen/react-cool-form/commit/a90c405a4a84b69855afa808afc1ef5d85252977) [#350](https://github.com/wellyshen/react-cool-form/pull/350) Thanks [@wellyshen](https://github.com/wellyshen)! - Fix(useForm): should warn for missing field name
## 0.0.112
### Patch Changes
- [`841e904`](https://github.com/wellyshen/react-cool-form/commit/841e9043e3a387c48bdf617f6ea845dfa70b8f20) [#345](https://github.com/wellyshen/react-cool-form/pull/345) Thanks [@wellyshen](https://github.com/wellyshen)! - Feat(useForm): support non
);
};
```
✨ Pretty easy right? React Cool Form is more powerful than you think. Let's [explore it](https://react-cool-form.netlify.app) 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.
- Featured on [React Status #245](https://react.statuscode.com/issues/245).
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
================================================
FILE: SECURITY.md
================================================
# Security Policy
## Supported Versions
Use this section to tell people about which versions of your project are
currently being supported with security updates.
| Version | Supported |
| ------- | ------------------ |
| 5.1.x | :white_check_mark: |
| 5.0.x | :x: |
| 4.0.x | :white_check_mark: |
| < 4.0 | :x: |
## Reporting a Vulnerability
Use this section to tell people how to report a vulnerability.
Tell them where to go, how often they can expect to get an update on a
reported vulnerability, what to expect if the vulnerability is accepted or
declined, etc.
================================================
FILE: app/.eslintignore
================================================
build
================================================
FILE: app/.eslintrc.js
================================================
module.exports = {
extends: ["react-app", "welly"],
rules: { "react/react-in-jsx-scope": "off" },
};
================================================
FILE: app/.gitignore
================================================
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
.pnp
.pnp.js
# testing
coverage
# production
build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.eslintcache
npm-debug.log*
yarn-debug.log*
yarn-error.log*
================================================
FILE: app/.prettierignore
================================================
# testing
coverage
# production
build
# misc
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
================================================
FILE: app/.stylelintrc.js
================================================
module.exports = {
extends: ["stylelint-config-standard", "stylelint-config-prettier"],
ignoreFiles: ["build/**/*.css"],
};
================================================
FILE: app/README.md
================================================
# App
🧪 A place for trying something interesting.
================================================
FILE: app/package.json
================================================
{
"name": "rcf-app",
"private": true,
"scripts": {
"link-pkg": "yarn link 'react-cool-form'",
"start:auto": "react-scripts start",
"start:dev": "REACT_APP_ENV=dev react-scripts start",
"start:prod": "yarn build && serve -s build",
"build": "react-scripts build",
"lint": "run-s lint:*",
"lint:code": "eslint --fix . --ext .js,.ts,.tsx",
"lint:type": "tsc",
"lint:style": "stylelint --fix \"**/*.{css,ts,tsx}\"",
"lint:format": "prettier -w . -u --loglevel silent",
"clean": "rimraf build",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"dependencies": {
"@emotion/react": "^11.4.0",
"@types/node": "^16.4.1",
"@types/react": "^17.0.14",
"@types/react-dom": "^17.0.9",
"normalize.css": "^8.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"typescript": "^4.3.5"
},
"devDependencies": {
"eslint-config-welly": "^1.13.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"serve": "^13.0.2",
"stylelint": "^13.13.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^22.0.0"
}
}
================================================
FILE: app/public/index.html
================================================
React Cool Form
================================================
FILE: app/public/manifest.json
================================================
{
"short_name": "REACT COOL IMG",
"name": "REACT COOL IMG",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
================================================
FILE: app/public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
================================================
FILE: app/src/App/index.tsx
================================================
import { Global, css } from "@emotion/react";
import normalize from "normalize.css";
import Playground from "../Playground";
import Automation from "../Automation";
import { root } from "./styles";
export default (): JSX.Element => (
<>
{process.env.REACT_APP_ENV === "dev" ? : }
>
);
================================================
FILE: app/src/App/styles.ts
================================================
import { css } from "@emotion/react";
// eslint-disable-next-line import/prefer-default-export
export const root = css`
body {
font-family: "Roboto", sans-serif;
}
`;
================================================
FILE: app/src/Automation/index.tsx
================================================
const Automation = (): JSX.Element =>
Automation
;
export default Automation;
================================================
FILE: app/src/Playground/index.tsx
================================================
/* eslint-disable no-console */
import { useForm } from "react-cool-form";
export default () => {
const { form, runValidation } = useForm({
// validate: () => ({ foo: "Required" }),
focusOnError: ["foo"],
});
return (
<>
>
);
};
================================================
FILE: app/src/index.tsx
================================================
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(
,
document.getElementById("root")
);
================================================
FILE: app/src/react-app-env.d.ts
================================================
///
///
================================================
FILE: app/src/types/index.d.ts
================================================
declare module "*.css";
================================================
FILE: app/tsconfig.json
================================================
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
================================================
FILE: babel.config.json
================================================
{
"presets": [
[
"@babel/env",
{
"loose": true,
"exclude": [
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-regenerator"
]
}
],
"@babel/typescript",
"@babel/react"
]
}
================================================
FILE: bundlesize.config.json
================================================
{
"files": [
{
"path": "dist/index.umd.production.min.js",
"maxSize": "7.2 kB"
}
]
}
================================================
FILE: docs/api-reference/use-controlled.md
================================================
---
id: use-controlled
title: useControlled
---
This hook allows us to integrate with an existing component (usually a [controlled component](https://reactjs.org/docs/forms.html#controlled-components)) or 3rd-party UI library in React Cool Form. With this hook, we can easily to create a reusable controller component to fulfill our needs. See the [useControlled Hook](../getting-started/3rd-party-ui-libraries#2-usecontrolled-hook) to learn more.
:::note
When working with [conditional fields](../examples/conditional-fields), please ensure the hook is wrapped in a component.
:::
```js
const [fieldProps, meta] = useControlled(name, config);
```
## Name
`string`
The name of the field. We must provide it when using this hook.
## Config
An `object` with the following options:
### formId
`string`
The [corresponding ID](./use-form#id) of the `useForm` hook. We only need it when using multiple form hooks at the same time.
### defaultValue
`string`
The default value of the field. Useful for dealing with the case of [conditional fields](../examples/conditional-fields).
### validation
`(value: any, values: FormValues) => any | Promise`
A synchronous/asynchronous function that is used for the [field-level validation](../getting-started/validation-guide#field-level-validation).
### parse
`(...args: any[]) => any`
A function that takes the event object (or parameters) of the target component's `onChange` handler and parses the value of the field that you want to store into the [form state](../getting-started/form-state#about-the-form-state). Useful for data type converting.
### format
`(value: any) => any`
A function that takes the field's value from the [form state](../getting-started/form-state#about-the-form-state) and formats the value to give to the field. Usually used in conjunction with `parse`.
### errorWithTouched
`boolean`
Enable/disable the feature of **filtering untouched errors**, which can help the user focus on typing without being annoyed by the error message. Default is `false`.
```js
// Current state: { errors: { foo: "Required" }, touched: {} }
// Returns "Required"
const [, { error }] = useControlled("foo");
// Current state: { errors: { foo: "Required" }, touched: {} }
// Returns undefined
const [, { error }] = useControlled("foo", { errorWithTouched: true });
// Current state: { errors: { foo: "Required" }, touched: { foo: true } }
// Returns "Required"
const [, { error }] = useControlled("foo", { errorWithTouched: true });
```
### ...restProps
Any other props that will be spread into the `fieldProps`.
## Field Props
An `object` with the following properties:
### name
`string`
The name of the field.
### value
`any`
The value of the field.
### onChange
`(...event: any[]) => void`
An event handler called when the field's value changed.
### onBlur
`(e: React.FocusEvent) => void`
An event handler called when the field loses focus.
### ...restProps
Any other props that were passed to the `config`.
## Meta
An `object` with the following properties:
### error
`string | undefined`
The current validation error of the field.
### isTouched
`boolean`
To indicate whether the field has been touched/visited.
### isDirty
`boolean`
To indicate whether the field has been modified.
## Example
The example demonstrates the basic usage of this hook.
:::note
When using the hook (and not working with [field-array](../getting-started/arrays-and-lists#dealing-with-array-fields)), a default value is required.
:::
```js
import { useControlled } from "react-cool-form";
const Field = ({
as,
name,
defaultValue,
validate,
parse,
format,
errorWithTouched,
...restProps
}) => {
const [fieldProps, { error, isTouched, isDirty }] = useControlled(name, {
defaultValue,
validate,
parse,
format,
errorWithTouched,
...restProps,
});
const Component = as;
return ;
};
```
================================================
FILE: docs/api-reference/use-field-array.md
================================================
---
id: use-field-array
title: useFieldArray
---
This hook supplies you with functions for manipulating the array/list of fields, it's fast! See the [Arrays and Lists](../getting-started/arrays-and-lists) to learn more.
```js
const [fields, helpers] = useFieldArray(name, config);
```
## Name
`string`
The name of the field. We must provide it when using this hook.
## Config
An `object` with the following options:
### formId
`string`
The [corresponding ID](./use-form#id) of the `useForm` hook. We only need it when using multiple form hooks at the same time.
### defaultValue
`string`
The default value of the field. Useful for dealing with the case of [conditional fields](../examples/conditional-fields).
### validation
`(value: any, values: FormValues) => any | Promise`
A synchronous/asynchronous function that is used for the [field-level validation](../getting-started/validation-guide#field-level-validation).
## Fields
`string[]`
An array that holds field names (e.g. `foo[0]`, `foo[1]`), which can be used for the `key` and `name` attributes of a field.
- It refers to the location of the field in the [form state](../getting-started/form-state#about-the-form-state). If the referenced value isn't an `array` type, returns an empty array instead.
- It doesn't include the field data. If you need to access the data, use the [use](./use-form#use) or [getState](./use-form#getstate) methods.
```js
const [fields] = useFieldArray("foo", { defaultValue: [{ name: "Iron Man" }] });
// The first parameter of the callback supplies you a field name (e.g. foo[0], foo[1])
fields.map((fieldName) => (
));
```
## Helpers
An `object` with the following methods:
### push
`(value: FieldValue, options?: Object) => void`
Add a value to the end of an array.
```js
const handleAdd = () => {
push(
{ name: "Iron Man" },
{
shouldTouched: false, // (Default = false) Set the field as touched
shouldDirty: true, // (Default = true) Set the field as dirty
}
);
};
```
### insert
`(index: number, value: FieldValue, options?: Object) => void`
Insert an element at a given index into the array.
```js
const handleInsert = () => {
insert(
0,
{ name: "Iron Man" },
{
shouldTouched: false, // (Default = false) Set the field as touched
shouldDirty: true, // (Default = true) Set the field as dirty
}
);
};
```
### swap
`(indexA: number, indexB: number) => void`
Swap two values in an array.
### move
`(from: number, to: number) => void`
Move an element in an array to another index.
### remove
`(index: number) => FieldValue`
Remove an element at an index of an array and return it.
## Example
The example demonstrates the basic usage of this hook.
```js
import { useForm, useFieldArray } from "react-cool-form";
const App = () => {
const { form } = useForm({
defaultValues: { foo: [{ name: "Iron Man" }] },
});
const [fields, { push, insert, move, swap, remove }] = useFieldArray("foo");
return (
);
};
```
================================================
FILE: docs/api-reference/use-form-methods.md
================================================
---
id: use-form-methods
title: useFormMethods
---
This hook allows us to use [all of the methods](./use-form#methods) provided by React Cool Form from a component at any level. See the [Do It Yourself](../getting-started/3rd-party-ui-libraries#3-do-it-yourself) to learn more.
```js
const methods = useFormMethods(formId);
```
## formId
`string`
The [corresponding ID](./use-form#id) of the `useForm` hook. We only need it when using multiple form hooks at the same time.
## methods
The [methods](./use-form#methods) are the same as the `useForm` hook.
## Example
The example demonstrates the basic usage of this hook.
```js
import { useFormMethods } from "react-cool-form";
const Field = ({ as, name, onFocus, ...restProps }) => {
const { clearErrors, ...otherMethods } = useFormMethods();
const Component = as;
return (
{
clearErrors(name);
if (onFocus) onFocus(e);
}}
{...restProps}
/>
);
};
```
================================================
FILE: docs/api-reference/use-form-state.md
================================================
---
id: use-form-state
title: useFormState
---
This hook can be used for two purposes:
- Isolating re-rendering: It helps us to isolate re-rendering at the component level for performance optimization (see [related article](https://overreacted.io/before-you-memo)). The API design similar to the [use](./use-form#use) method of the `useForm` that maintain a consistent DX for us. See the [Isolating Re-rendering](../getting-started/form-state#isolating-re-rendering) to learn more.
- On state change event: To listen for changes to properties in the [form state](../getting-started/form-state#about-the-form-state) without triggering re-renders. See the [On State Change Event](../getting-started/form-state#on-state-change-event) to learn more.
```js
// Isolating re-rendering mode
const props = useFormState(path, config);
// On state change event mode
useFormState(path, callback, formId);
```
## Path
`string | string[] | Record`
The path of the property we want to access from the [form state](../getting-started/form-state#about-the-form-state). We can construct the return values as follows.
- Every time an accessed value changed that will trigger re-renders. Thus, there're [some guidelines](../getting-started/form-state#best-practices) for us to use the form state.
- You can access the form's values without the `values.` prefix, ya! it's a shortcut for for your convenience.
```js
// Getting a value
const foo = useFormState("values.foo");
// Shortcut for getting a value
const foo = useFormState("foo");
// Array pick
const [foo, bar] = useFormState(["values.foo", "values.bar"]);
// Object pick
const { foo, bar } = useFormState({ foo: "values.foo", bar: "values.bar" });
```
## Config
An `object` with the following options:
### formId
`string`
The [corresponding ID](./use-form#id) of the `useForm` hook. We only need it when using multiple form hooks at the same time.
### defaultValues
`FormValues`
The alternative default values for this hook to return when we didn't provide them via the [defaultValues option](./use-form#defaultvalues) of the `useForm`. Two common use cases of this option are as follows:
- Setting a default value for a field via the `defaultValue` attribute.
- Setting a default value for a field via the `useControlled`'s [defaultValue option](./use-controlled#defaultvalue).
### errorWithTouched
`boolean`
Enable/disable the feature of **filtering untouched errors**, which can help the user focus on typing without being annoyed by the error message. Default is `false`.
```js
// Current state: { errors: { foo: "Required" }, touched: {} }
// Returns { foo: "Required" }
const errors = useFormState("errors");
// Current state: { errors: { foo: "Required" }, touched: {} }
// Returns {}
const errors = useFormState("errors", { errorWithTouched: true );
// Current state: { errors: { foo: "Required" }, touched: { foo: true } }
// Returns { foo: "Required" }
const errors = useFormState("errors", { errorWithTouched: true );
```
## Callback
`(props: any) => void`
It's called on any of the subscribed properties in the [form state](../getting-started/form-state#about-the-form-state) change. It takes the properties as the parameter.
## FormId
`string`
An optional parameter that works the same as the [config.formId](#formid).
## Example
The example demonstrates the basic usage of this hook.
```js
import { useFormState } from "react-cool-form";
// To isolate re-rendering at the component level
const IsolatedComponent = () => {
const foo = useFormState("foo");
return
{foo}
;
};
// To listen for the changes of a field value
useFormState("foo", (foo) => console.log(foo));
```
================================================
FILE: docs/api-reference/use-form.md
================================================
---
id: use-form
title: useForm
---
This is a custom React [hook](https://reactjs.org/docs/hooks-custom.html#using-a-custom-hook) that helps you with building forms. It takes `config` parameters and returns useful methods as follows.
```js
const methods = useForm(config);
```
## Config
An `object` with the following options:
### id
`string`
The ID of the hook, it's used to pair with the related hook(s) of React Cool Form. We only need it when using multiple form hooks at the same time.
### defaultValues
`Record`
Default field values of the form. In most case (especially working with TypeScript), we should use it to initialize a field's value and use the [defaultValue/defaultChecked](https://reactjs.org/docs/uncontrolled-components.html#default-values) attribute for the case of [conditional fields](../examples/conditional-fields). The `defaultValues` also used to compare against the current values to calculate `isDirty` and `dirty`.
- The `defaultValues` is cached **at the first render** within the custom hook. If you want to reset it or [lazily set it](../examples/lazy-default-values), you can use the [reset](#reset) method.
### excludeFields
`string[]`
Tell React Cool Form to exclude field(s) by passing in the `name`/`id`/`class` of the field. You can also exclude a field via the pre-defined `data-rcf-exclude` attribute.
- The `excludeFields` and `data-rcf-exclude` won't affect the functionality of the [useControlled](./use-controlled).
```js {3,12}
const App = () => {
const { form } = useForm({
excludeFields: ["foo", "#bar", ".baz"],
});
return (
);
};
```
👉🏻 See the [Exclude Fields](../getting-started/integration-an-existing-form#exclude-fields) to learn more.
### builtInValidationMode
`"message" | "state" | false`
We can configure the [mode of the built-in validation](../getting-started/validation-guide#displaying-error-messages) as follows:
- `"message"` (default): Returns [a localized message](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage) that describes the validation constraints that the field does not satisfy (if any)
- `"state"`: Returns the **key of the invalid property** (e.g. "valueMissing", "tooShort", etc.) of the [ValidityState](https://developer.mozilla.org/en-US/docs/Web/API/ValidityState) (if any)
- `false`: Disable the [built-in validation](../getting-started/validation-guide#built-in-validation)
### validateOnChange
`boolean`
Tell React Cool Form to run validations on `change` events as well as the [setValue](#setvalue) method. Default is `true`.
### validateOnBlur
`boolean`
Tell React Cool Form to run validations on `blur` events. Default is `true`.
### focusOnError
`boolean | string[] | (names: string[]) => string[]`
Tell React Cool Form to apply focus to the first field with an error upon an attempted form submission. Default is `true`.
- Only native input elements that support [HTMLElement.focus()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus) will work.
- The focus order is based on the field order (i.e. top-to-bottom and left-to-right).
```js
// Current fields: { foo: "", bar: "", baz: "" }
// Disable this feature
const methods = useForm({ focusOnError: false });
// Change the focus order by passing in field names
const methods = useForm({ focusOnError: ["bar", "foo", "baz"] });
// Change the focus order by modifying existing field names
const methods = useForm({
focusOnError: (names) => {
[names[0], names[1]] = [names[1], names[0]];
return names;
},
});
```
### removeOnUnmounted
`boolean | string[] | (names: string[]) => string[]`
By default, React Cool Form automatically removes the **related state** (i.e. value, error, touched, dirty) and **default value** of an unmounted field for us. However, we can set the `removeOnUnmounted` to `false` to maintain all the data or give it field names to maintain partial data. Default is `true`.
- To keep a default value existing between a dynamically show/hide field, we can set it via `defaultValue` attribute or option.
- If this feature doesn't meet your needs, you can use the [removeField](#removefield) to control what data that you want to remove instead.
```js
// Current values: { foo: "🍎", bar: "🍋", baz: "🥝" }
// Keep all the data
const methods = useForm({ removeOnUnmounted: false });
// Keep partial data (i.e. "bar" and "baz") by passing in field names
const methods = useForm({ removeOnUnmounted: ["foo"] });
// Keep partial data (i.e. "bar" and "baz") by modifying existing field names
const methods = useForm({
removeOnUnmounted: (names) => names.filter((name) => name === "foo"),
});
```
👉🏻 See the [conditional fields](../examples/conditional-fields) example to learn more.
### validate
`(values: FormValues) => FormErrors | false | void | Promise`
A synchronous/asynchronous function that is used for the [form-level validation](../getting-started/validation-guide#form-level-validation). It takes all the form's values and returns any validation errors (or returns `undefined` if there's no error). The validation errors must be in the same shape as the values of the form.
### onSubmit
`(values: FormValues, options: Object, e?: Event) => void | Promise`
The form submission handler will be called when the form is submitted (or when the [submit](#submit) method is called) and validated successfully. It takes the following parameters:
```js
const methods = useForm({
onSubmit: async (
values,
{
getState,
setValue,
setTouched,
setDirty,
setError,
focus,
runValidation,
removeField,
submit,
reset,
},
e
) => {
/* Do something... */
},
});
```
👉🏻 See the [Form Submission](../getting-started/form-submission) to learn more.
### onError
`(errors: FormErrors, options: Object, e?: Event) => void`
The form error handler that is called when the form is submitted (or when the [submit](#submit) method is called) and validated failed. It takes the following parameters:
```js
const methods = useForm({
onError: (
errors,
{
getState,
setValue,
setTouched,
setDirty,
setError,
focus,
runValidation,
removeField,
submit,
reset,
},
e
) => {
/* Do something... */
},
});
```
👉🏻 See the [Form Submission](../getting-started/form-submission) to learn more.
### onReset
`(values: FormValues, options: Object, e?: Event) => void`
The form reset handler that is called when the form is reset (or when the [reset](#reset) method is called). It takes the following parameters:
```js
const methods = useForm({
onReset: (
values,
{
getState,
setValue,
setTouched,
setDirty,
setError,
focus,
runValidation,
removeField,
submit,
reset,
},
e
) => {
/* Do something... */
},
});
```
👉🏻 See the [Reset Form](../getting-started/reset-form) to learn more.
### onStateChange
`(formState: FormState) => void`
The form state change handler that is called on every state change. It's useful for **debugging** or **triggering a handler**.
- Want to trigger a handler based on certain properties in the form state? Check out the [useFormState](./use-form-state) to learn more.
- `formState` is readonly and should not be mutated directly.
```js
const methods = useForm({
onStateChange: (formState) => console.log("State: ", formState),
});
```
## Methods
An `object` with the following methods:
### form
`(element: HTMLElement) => void`
This method allows us to integrate [an existing form](../getting-started/integration-an-existing-form#hook-into-a-form) or [a container where inputs are used](../getting-started/integration-an-existing-form#without-using-a-form-element) with React Cool Form.
### field
`(validateOrOptions: Function | Object) => Function`
This method allows us to do [field-level validation](../getting-started/validation-guide#field-level-validation) and data type conversion via the `ref` attribute. For the data type conversion, React Cool Form supports the [valueAsNumber](https://www.w3.org/TR/2011/WD-html5-20110405/common-input-element-attributes.html#dom-input-valueasnumber), [valueAsDate](https://www.w3.org/TR/2011/WD-html5-20110405/common-input-element-attributes.html#dom-input-valueasdate), and custom parser.
- For your convenience, the values of `` and `` are converted to `number` by default.
- When using this method with the [useControlled](./use-controlled), the functionality of the method will be replaced.
```js
const { field } = useForm();
!value.length && "Required",
valueAsNumber: true, // (Default = false) Returns a number representing the field's value if applicable, otherwise, returns "NaN"
valueAsDate: true, // (Default = false) Returns a Date object representing the field's value if applicable, otherwise, returns "null"
parse: (value) => customParser(value), // Returns whatever value you want through the callback
})}
/>;
```
If you just want to validate the field, there's a shortcut for it:
```js
!value.length && "Required")} />
```
### focus
`(name: string, delay?: number) => void`
This method allows us to apply focus to a field. If you want to focus on the first field of a nested fields, you can just pass in the parent path as below.
:::note
When working with [Arrays and Lists](../getting-started/arrays-and-lists), we need to set `delay` (delay = 0 is acceptable) to wait for a field rendered before applying focus to it.
:::
```js {7,12}
const App = () => {
const { form, focus } = useForm();
useEffect(() => {
// Will focuses on the first field after 0.5 second
// It works the same as `focus("foo.a", 500)`
focus("foo", 500);
}, []);
return (
);
};
```
👉🏻 See the [Applying Focus](../getting-started/arrays-and-lists#applying-focus) to learn more.
### use
`(path: string | string[] | Record, options?: Object) => any`
This method provides us a performant way to use the form state with minimized re-renders. See the [Form State](../getting-started/form-state) to learn more.
### getState
`(path?: string | string[] | Record) => any`
This method allows us to read the form state without triggering re-renders. See the [Reading the State](../getting-started/form-state#reading-the-state) to learn more.
### setValue
`(name: string, value: any | Function, options?: Object) => void`
This method allows us to manually set/clear the value of a field. Useful for creating custom field change handlers.
```js
const { setValue } = useForm();
setValue("fieldName", "value", {
shouldValidate: true, // (Default = "validateOnChange" option) Triggers field validation
shouldTouched: true, // (Default = true) Sets the field as touched
shouldDirty: true, // (Default = true) Sets the field as dirty
});
// We can also pass a callback as the "value" parameter, similar to React's setState callback style
setValue("fieldName", (prevValue) => prevValue.splice(2, 0, "🍎"));
```
We can clear the value of a field by the following way:
```js
setValue("fieldName", undefined); // The field will be unset: { fieldName: "value" } → {}
```
### setTouched
`(name: string, isTouched?: boolean, options?: Object) => void`
This method allows us to manually set/clear the touched of a field. Useful for creating custom field touched handlers.
```js
const { setTouched } = useForm();
// Common use case
setTouched("fieldName");
// Full parameters
setTouched(
"fieldName",
true, // (Default = true) Sets the field as touched
{
shouldValidate: true, // (Default = "validateOnBlur" option) Triggers field validation
}
);
```
We can clear the touched of a field by the following way:
```js
setTouched("fieldName", false); // The touched will be unset: { fieldName: true } → {}
```
### setDirty
`(name: string, isDirty?: boolean) => void`
This method allows us to manually set/clear the dirty of a field. Useful for creating custom field dirty handlers.
```js
const { setDirty } = useForm();
// Common use case
setDirty("fieldName");
```
We can clear the dirty of a field by the following way:
```js
setDirty("fieldName", false); // The dirty will be unset: { fieldName: true } → {}
```
### setError
`(name: string, error: any | Function) => void`
This method allows us to manually set/clear the error of a field. Useful for creating custom field error handlers.
```js
const { setError } = useForm();
setError("fieldName", "Required");
// We can also pass a callback as the "error" parameter, similar to React's setState callback style
setError("fieldName", (prevError) => (prevError ? "Too short" : "Required"));
```
We can clear the error of a field by the following way (or using [clearErrors](#clearerrors)):
```js
setError("fieldName", undefined); // Or any falsy values, the error will be unset: { fieldName: "Required" } → {}
```
### clearErrors
`(name?: string | string[]) => void`
This method allows us to manually clear errors (or an error). Useful for creating custom field error handlers.
```js
const { clearErrors } = useForm();
// Current errors: { foo: { bar: "Required", baz: "Required" }, qux: "Required" }
clearErrors(); // Clears all errors. Result: {}
clearErrors("foo"); // Clears both "foo.bar" and "foo.baz". Result: { qux: "Required" }
clearErrors(["foo.bar", "foo.baz"]); // Clears "foo.bar" and "foo.baz" respectively. Result: { foo: {}, qux: "Required" }
```
### runValidation
`(name?: string | string[], options?: Object) => Promise`
This method allows us to manually run validation for the form or field(s).
- It returns a `boolean` that indicates the validation results, `true` means valid, `false` otherwise.
- Please note, when enabling the [Filter Untouched Field Errors](../getting-started/form-state#filter-untouched-field-errors), only the errors of the touched fields are accessible.
```js
const { runValidation } = useForm();
// Validates the form (i.e. all the fields)
runValidation();
// Validates single field
runValidation("fieldName");
// Validates multiple fields
runValidation(["fieldName1", "fieldName2"]);
// With result
const validateForm = async () => {
const isValid = await runValidation();
console.log("The form is: ", isValid ? "valid" : "invalid");
};
// Full parameters
runValidation("fieldName", {
shouldFocus: true, // (Default = "focusOnError" option) To focus to the first field with an error within the specified fields
});
```
👉🏻 See the [Validation Guide](../getting-started/validation-guide) to learn more.
### removeField
`(name: string, exclude?: string[]) => void`
This method allows us to manually remove the **related state** (i.e. value, error, touched, dirty) and **default value** of a field, it also excludes a field from the form.
- By default, React Cool Form automatically [removes an unmounted field](#removeonunmounted) for us but this method gives us the ability to control what data that we want to remove.
```js {4,10}
const App = () => {
const [show, setShow] = useState(true);
const { form, removeField } = useForm({
removeOnUnmounted: false, // Disable the feature of automatically removing fields
});
const handleToggle = () => {
setShow(!show);
// We can exclude these data: ["defaultValue", "value", "error", "touched", "dirty"]
if (!show) removeField("foo", ["defaultValue"]); // Keep the default value
};
return (
);
};
```
### submit
`(e?: Event) => Promise`
This method allows us to manually submit the form, it returns a promise with the following results. Useful for meeting the needs of custom design.
- Returns a promise with `errors` when any validation errors
- Returns a promise with `values` when the form is validated successfully
```js
const { submit } = useForm({
onSubmit: (values, options, e) => console.log("onSubmit: ", values), // Triggered on form submit + valid
onError: (errors, options, e) => console.log("onError: ", errors), // Triggered on form submit + invalid
});
const handleFormSubmit = async (e) => {
const { errors, values } = await submit(e); // Pass the event object to the event handlers
if (errors) {
// Do something for invalid case
} else {
// Do something for valid case
}
};
```
👉🏻 See the [Form Submission](../getting-started/form-submission) to learn more.
### reset
`(values?: FormValues | Function | null, exclude?: string[] | null, e?: Event) => void`
This method allows us to manually reset the form. It will restore the form to its default values as well as reset/clear all the [related state](../getting-started/form-state#about-the-form-state).
- We can pass `values` as an optional parameter to update the default values.
- We can pass `exclude` as an optional parameter to prevent specific [state](../getting-started/form-state#about-the-form-state) from reset.
```js
const { reset } = useForm({
defaultValues: { firstName: "", lastName: "" },
onReset: (values, options, e) => console.log("onReset: ", values), // Triggered on form reset
});
const handleFormReset = (e) => {
reset(
{ firstName: "Welly", lastName: "Shen" }, // Update the default values
["isSubmitted", "submitCount"], // Don't reset the "isSubmitted" and "submitCount" state
e // Pass the event object to the "onReset" handler
);
// We can also pass a callback as the "values" parameter, similar to React's setState callback style
reset((prevValues) => ({ ...prevValues, firstName: "Bella" }));
};
```
👉🏻 See the [Reset Form](../getting-started/reset-form) to learn more.
================================================
FILE: docs/api-reference/utility-functions.md
================================================
---
id: utility-functions
title: Utility Functions
---
React Cool Form exports useful utility functions that can help you handle [complex structures](../getting-started/complex-structures) efficiently.
```js
import { get, set, unset } from "react-cool-form";
```
## get
`(object: Record, path: string, defaultValue?: unknown) => any`
Gets the value at path of object. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
```js {8}
import { useForm, get } from "react-cool-form";
const { form } = useForm({
defaultValues: { foo: { bar: { baz: "" } } },
validate: (values) => {
const errors = {};
if (!get(values, "foo.bar.baz", "")) errors.foo.bar.baz = "Required";
return errors;
},
// ...
});
```
## set
`(object: Record, path: string, value: unknown, immutable?: boolean) => any`
Sets the value at `path` of `object`. If a portion of `path` doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties.
```js {10,12}
import { useForm, set } from "react-cool-form";
const { form } = useForm({
defaultValues: { foo: { bar: { baz: "" } } },
validate: (values) => {
const errors = {};
if (!values.foo.bar.baz) {
// Mutable way
set(errors, "foo.bar.baz", "Required");
// Immutable way
errors = set(errors, "foo.bar.baz", "Required", true);
}
return errors;
},
// ...
});
```
## unset
`(object: Record, path: string, immutable?: boolean) => any`
Removes the property at `path` of `object`.
- If the property remains empty, the parent properties will be removed as well.
- It will clear the redundant `empty` or `undefined` element(s) of an array.
```js {12,14}
import { useForm, unset } from "react-cool-form";
const { form } = useForm({
defaultValues: { foo: { bar: { baz: "" } } },
validate: (values) => {
const errors = {};
if (!values.foo.bar.baz) {
// ...
} else {
// Mutable way
unset(errors, "foo.bar.baz");
// Immutable way
errors = unset(errors, "foo.bar.baz", true);
}
return errors;
},
// ...
});
```
================================================
FILE: docs/examples/arrays-and-lists.md
================================================
---
id: arrays-and-lists
title: Arrays and Lists
hide_table_of_contents: true
---
This example demonstrates how to work with array fields in React Cool Form.
================================================
FILE: docs/examples/basic.md
================================================
---
id: basic
title: Basic
hide_table_of_contents: true
---
This example demonstrates how to use form inputs (input, select, and textarea) to build a form with no validation.
================================================
FILE: docs/examples/built-in-validation.md
================================================
---
id: built-in-validation
title: Built-in Validation
hide_table_of_contents: true
---
This example demonstrates how to use [HTML form validation](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#Using_built-in_form_validation) to validate a form.
================================================
FILE: docs/examples/checkboxes.md
================================================
---
id: checkboxes
title: Checkboxes
hide_table_of_contents: true
---
This example demonstrates how to use React Cool Form with a checkbox group and how to validate it. Given that fields all the share `name` and the respective `value`, React Cool Form will automatically bind them into a single array.
================================================
FILE: docs/examples/complex-strcutures.md
================================================
---
id: complex-structures
title: Complex Structures
hide_table_of_contents: true
---
This example demonstrates how to handle [Complex Structures](../getting-started/complex-structures) in React Cool Form.
================================================
FILE: docs/examples/conditional-fields.md
================================================
---
id: conditional-fields
title: Conditional Fields
hide_table_of_contents: true
---
By default, when a form input element ([input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input), [select](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select), and [textarea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)) is unmounted, React Cool Form will auto remove it for us. Useful for dealing with conditional fields, let's take a look at the following example:
================================================
FILE: docs/examples/custom-field.md
================================================
---
id: custom-field
title: Custom Field
hide_table_of_contents: true
---
This example demonstrates how to combine the [useFormState](../api-reference/use-form-state) and [useFormMethods](../api-reference/use-form-methods) to DIY a custom field.
================================================
FILE: docs/examples/field-level-validation.md
================================================
---
id: field-level-validation
title: Field-level Validation
hide_table_of_contents: true
---
This example demonstrates how to validate a form by the [field](../api-reference/use-form#field) method of React Cool Form.
================================================
FILE: docs/examples/form-level-validation.md
================================================
---
id: form-level-validation
title: Form-level Validation
hide_table_of_contents: true
---
This example demonstrates how to validate a form by the [validate](../api-reference/use-form#validate) option of React Cool Form.
================================================
FILE: docs/examples/form-submission.md
================================================
---
id: form-submission
title: Form Submission
hide_table_of_contents: true
---
This example demonstrates how to submit a form in React Cool Form.
================================================
FILE: docs/examples/isolating-rerendering.md
================================================
---
id: isolating-rerendering
title: Isolating Re-rendering
hide_table_of_contents: true
---
This example demonstrates how to isolate re-rendering at the component level via the [useFormState](../api-reference/use-form-state) hook.
================================================
FILE: docs/examples/lazy-default-values.md
================================================
---
id: lazy-default-values
title: Lazy Default Values
hide_table_of_contents: true
---
This example demonstrates how to set [defaultValues](../api-reference/use-form#defaultvalues) lazily.
================================================
FILE: docs/examples/material-ui.md
================================================
---
id: material-ui
title: Material-UI
hide_table_of_contents: true
---
This example demonstrates the easiest way to integrate [Material-UI](https://material-ui.com) with your form that you have never seen 😎.
================================================
FILE: docs/examples/multi-select.md
================================================
---
id: multi-select
title: Multi-select
hide_table_of_contents: true
---
This example demonstrates how to use React Cool Form with a multi-select input. Given the select element a `multiple` attribute. React Cool Form will automatically bind the options into a single array.
================================================
FILE: docs/examples/radio-group.md
================================================
---
id: radio-group
title: Radio Group
hide_table_of_contents: true
---
This example demonstrates how to use React Cool Form with a radio group.
================================================
FILE: docs/examples/react-select.md
================================================
---
id: react-select
title: React Select
hide_table_of_contents: true
---
This example demonstrates how to use React Cool Form's [useControlled](../api-reference/use-controlled) hook to integrate [React Select](https://react-select.com) with your form.
================================================
FILE: docs/examples/reset-form.md
================================================
---
id: reset-form
title: Reset Form
hide_table_of_contents: true
---
This example demonstrates how to reset a form in React Cool Form.
================================================
FILE: docs/examples/validation-with-schema.md
================================================
---
id: validation-with-schema
title: Validation with Schema
hide_table_of_contents: true
---
This example demonstrates how to validate a form with a 3rd-party (e.g. [Yup](https://github.com/jquense/yup) or [Joi](https://github.com/sideway/joi)).
================================================
FILE: docs/examples/virtualized-lists.md
================================================
---
id: virtualized-lists
title: Virtualized Lists
hide_table_of_contents: true
---
When working with millions of list items, I'd like to recommend using [React Cool Virtual](https://github.com/wellyshen/react-cool-virtual) to virtualized the list for better performance. It works nicely with React Cool Form, let's dive into it.
================================================
FILE: docs/examples/without-form-element.md
================================================
---
id: without-form-element
title: Without
);
};
```
## 2. [useControlled Hook](../api-reference/use-controlled)
[Controlled components](https://reactjs.org/docs/forms.html#controlled-components) with highly customized and full features like [React Select](https://react-select.com) or [React Datepicker](https://reactdatepicker.com). We can use React Cool Form's [useControlled](../api-reference/use-controlled) hook to create a reusable controller component for them in a flexible and performant way.
:::note
When using the hook (and not working with [field-array](./arrays-and-lists#dealing-with-array-fields)), a default value is required.
:::
[](https://codesandbox.io/s/rcf-react-select-djsl1?fontsize=14&hidenavigation=1&theme=dark)
```js
import { useForm, useControlled } from "react-cool-form";
import Select from "react-select";
const Field = ({ as, name, ...restProps }) => {
const [fieldProps] = useControlled(name, restProps);
const Component = as;
return ;
};
const options = [
{ label: "React", value: "react" },
{ label: "Vue", value: "vue" },
{ label: "Angular", value: "angular" },
{ label: "Svelte", value: "svelte" },
];
const App = () => {
const { form } = useForm({
defaultValues: { framework: "" }, // We must provide a default value for the controlled field
excludeFields: ["#framework"], // Exclude the internal input element of React-Select by ID
onSubmit: (values) => console.log("onSubmit: ", values),
});
return (
);
};
```
## 3. Do It Yourself
If the above solutions can't meet your needs then you can set up a custom field with the [API](../api-reference/use-form#methods) of React Cool Form. The following example demonstrates how to combine the [useFormState](../api-reference/use-form-state) and [useFormMethods](../api-reference/use-form-methods) to DIY a custom field with full validation UX.
[](https://codesandbox.io/s/rcf-custom-field-p9lqi?fontsize=14&hidenavigation=1&theme=dark)
```js
import { useForm, useFormState, useFormMethods } from "react-cool-form";
import { TextField, Button } from "@material-ui/core";
const Field = ({ as, name, onChange, onBlur, ...restProps }) => {
const value = useFormState(`values.${name}`);
const { setValue, setTouched } = useFormMethods();
const Component = as;
return (
{
setValue(name, e.target.value); // Update the field's value and set it as touched
if (onChange) onChange(e);
}}
onBlur={(e) => {
setTouched(name); // Set the field as touched for displaying error (if it's not touched)
if (onBlur) onBlur(e);
}}
{...restProps}
/>
);
};
const App = () => {
const { form, use } = useForm({
defaultValues: { username: "" },
// excludeFields: ["username"], // You can also exclude the field here
validate: ({ username }) => {
const errors = {};
if (!username.length) errors.username = "Required";
return errors;
},
onSubmit: (values) => console.log("onSubmit: ", values),
});
const errors = use("errors");
return (
);
};
```
================================================
FILE: docs/getting-started/accessibility.md
================================================
---
id: accessibility
title: Accessibility (a11y)
hide_table_of_contents: true
---
Web accessibility (a.k.a [a11y](https://en.wiktionary.org/wiki/a11y)) is the design and creation of websites that can be used by everyone. Accessibility support is necessary to allow assistive technology to interpret web pages. React Cool Form is designed to keep your input elements **clean** that helps you build accessible forms by using standard HTML techniques.
- Provide [`