Repository: final-form/react-final-form Branch: main Commit: fcea1a1af63a Files: 293 Total size: 748.1 KB Directory structure: gitextract_z4w9ccys/ ├── .babelrc.js ├── .eslintrc ├── .flowconfig ├── .github/ │ ├── CODEOWNERS │ ├── CODE_OF_CONDUCT.md │ ├── CONTRIBUTING.md │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE.md │ ├── PULL_REQUEST_TEMPLATE.md │ └── workflows/ │ ├── ci.yml │ └── lock.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .travis.yml ├── LICENSE ├── MIGRATION_V7.md ├── README.md ├── docs/ │ ├── api/ │ │ ├── Field.md │ │ ├── Form.md │ │ ├── FormSpy.md │ │ ├── useField.md │ │ ├── useForm.md │ │ └── useFormState.md │ ├── api.md │ ├── examples/ │ │ ├── chakra.md │ │ ├── field-level-validation.md │ │ ├── record-level-validation.md │ │ ├── simple.md │ │ ├── submission-errors.md │ │ ├── subscriptions.md │ │ └── wizard.md │ ├── examples.md │ ├── faq.md │ ├── getting-started.md │ ├── migration/ │ │ ├── formik.md │ │ └── redux-form.md │ ├── philosophy.md │ └── types/ │ ├── FieldProps.md │ ├── FieldRenderProps.md │ ├── FormProps.md │ ├── FormRenderProps.md │ ├── FormSpyProps.md │ └── FormSpyRenderProps.md ├── eslint.config.mjs ├── examples/ │ ├── async-field-level-validation/ │ │ ├── Spinner.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── async-redux-submission/ │ │ ├── Styles.js │ │ ├── asyncSubmissionMiddleware.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ ├── registrationDuck.js │ │ └── store.js │ ├── async-typeahead-redux/ │ │ ├── GithubUserTypeahead.jsx │ │ ├── Styles.js │ │ ├── actions.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ ├── store.js │ │ └── useKeyword.js │ ├── auto-save-field-blur/ │ │ ├── AutoSave.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── auto-save-selective-debounce/ │ │ ├── AutoSave.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── auto-save-with-debounce/ │ │ ├── AutoSave.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── calculated-fields/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── chakra/ │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── validate.js │ ├── conditional-fields/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ ├── pickupTimes.js │ │ └── readme.md │ ├── credit-card/ │ │ ├── Card.js │ │ ├── Styles.js │ │ ├── cardUtils.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── sandbox.config.json │ ├── custom-validation-engine/ │ │ ├── OnBlurValidation.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── debounced-record-level-validation/ │ │ ├── ErrorWithDelay.js │ │ ├── README.md │ │ ├── Styles.js │ │ ├── index.js │ │ └── package.json │ ├── declarative-form-rules/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── downshift-typeahead/ │ │ ├── DownshiftInput.js │ │ ├── Styles.js │ │ ├── fruit.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── external-submit/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── field-arrays/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── field-level-validation/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── field-warnings/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── warning-engine.js │ ├── fields-component/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── focus-first-error/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── validate.js │ ├── format-on-blur/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── format-string-by-pattern/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── hybrid-sync-async-record-level-validation/ │ │ ├── Spinner.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── independent-error-component-render-props/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── independent-error-component-with-hooks/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── listening-for-external-changes/ │ │ ├── BooleanDecay.js │ │ ├── ExternalModificationDetector.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── loading-initializing-values/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── loading-saving-reinitializing/ │ │ ├── LoadSaveReinitializeForm.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── material-ui/ │ │ ├── .prettierrc │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── parse-format/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── prefixed-fields/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── readme.md │ ├── record-level-validation/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── redux/ │ │ ├── FormStateFromRedux.js │ │ ├── FormStateToRedux.js │ │ ├── Styles.js │ │ ├── finalFormDuck.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── store.js │ ├── reusable-field-groups/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── simple/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── strongly-typed-values-typescript/ │ │ ├── Styles.tsx │ │ ├── components/ │ │ │ ├── CheckboxInput.tsx │ │ │ ├── MultiCheckboxInput.tsx │ │ │ ├── MultiSelectInput.tsx │ │ │ ├── NumberInput.tsx │ │ │ ├── RadioInput.tsx │ │ │ ├── SelectInput.tsx │ │ │ ├── TextAreaInput.tsx │ │ │ └── TextInput.tsx │ │ ├── index.tsx │ │ └── readme.md │ ├── styling-with-smooth-ui/ │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── submission-errors/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── subscriptions/ │ │ ├── RenderCount.js │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ └── readme.md │ ├── third-party-components/ │ │ ├── Styles.js │ │ ├── index.js │ │ ├── package.json │ │ ├── readme.md │ │ └── states.js │ └── wizard/ │ ├── Styles.js │ ├── Wizard.js │ ├── index.js │ ├── package.json │ └── readme.md ├── package-scripts.js ├── package.json ├── rollup.config.mjs ├── src/ │ ├── Field.test.js │ ├── Field.tsx │ ├── FormSpy.test.js │ ├── FormSpy.tsx │ ├── ReactFinalForm.test.js │ ├── ReactFinalForm.tsx │ ├── context.test.js │ ├── context.ts │ ├── getValue.test.js │ ├── getValue.ts │ ├── getters.ts │ ├── index.ts │ ├── isReactNative.ts │ ├── isSyntheticEvent.ts │ ├── renderComponent.test.js │ ├── renderComponent.ts │ ├── shallowEqual.test.js │ ├── shallowEqual.ts │ ├── testUtils.ts │ ├── types.ts │ ├── useConstant.ts │ ├── useConstantCallback.test.js │ ├── useConstantCallback.ts │ ├── useField.dynamic-name-869.test.js │ ├── useField.test.js │ ├── useField.ts │ ├── useForm.test.js │ ├── useForm.ts │ ├── useFormState.test.js │ ├── useFormState.ts │ ├── useLatest.ts │ └── useWhenValueChanges.ts ├── tsconfig.build.json ├── tsconfig.json ├── tslint.json └── typescript/ ├── Field.test.tsx ├── FormSpy.test.tsx ├── ReactFinalForm.test.tsx ├── index.d.ts ├── tsconfig.json ├── useField.test.tsx └── useFormState.test.tsx ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc.js ================================================ const { NODE_ENV } = process.env; const test = NODE_ENV === "test"; const loose = true; module.exports = { presets: [ [ "@babel/preset-env", { loose, ...(test ? { targets: { node: "8" } } : {}), }, ], "@babel/preset-react", "@babel/preset-typescript", ], plugins: [ "@babel/plugin-syntax-dynamic-import", "@babel/plugin-syntax-import-meta", test && "@babel/plugin-transform-react-jsx-source", ].filter(Boolean), }; ================================================ FILE: .eslintrc ================================================ { "extends": "react-app", "plugins": ["react-hooks"], "rules": { "jsx-a11y/href-no-hash": 0, "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn", "import/no-anonymous-default-export": 0 } } ================================================ FILE: .flowconfig ================================================ [ignore] dist [include] [libs] [options] ================================================ FILE: .github/CODEOWNERS ================================================ * @erikras ================================================ FILE: .github/CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at rasmussenerik@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ================================================ FILE: .github/CONTRIBUTING.md ================================================ # Contributing Thanks for your interest in contributing to 🏁 React Final Form! Please take a moment to review this document **before submitting a pull request**. We are open to, and grateful for, any contributions made by the community. ## Reporting issues and asking questions Before opening an issue, please search the [issue tracker](https://github.com/final-form/react-final-form/issues) to make sure your issue hasn’t already been reported. **We use the issue tracker to keep track of bugs and improvements** to 🏁 React Final Form itself, its examples, and the documentation. We encourage you to open issues to discuss improvements, architecture, internal implementation, etc. If a topic has been discussed before, we will ask you to join the previous discussion. For support or usage questions, please search and ask on [StackOverflow with a `react-final-form` tag](https://stackoverflow.com/questions/tagged/react-final-form). We ask you to do this because StackOverflow has a much better job at keeping popular questions visible. Unfortunately good answers get lost and outdated on GitHub. **If you already asked at StackOverflow and still got no answers, post an issue with the question link, so we can either answer it or evolve into a bug/feature request.** ## Sending a pull request **Please ask first before starting work on any significant new features.** It's never a fun experience to have your pull request declined after investing a lot of time and effort into a new feature. To avoid this from happening, we request that contributors create [an issue](https://github.com/final-form/react-final-form/issues) to first discuss any significant new features. Please try to keep your pull request focused in scope and avoid including unrelated commits. After you have submitted your pull request, we’ll try to get back to you as soon as possible. We may suggest some changes or improvements. Please format the code before submitting your pull request by running: ```sh npm run precommit ``` ## Coding standards Our code formatting rules are defined in [.eslintrc](https://github.com/final-form/react-final-form/blob/master/.eslintrc). You can check your code against these standards by running: ```sh npm start lint ``` To automatically fix any style violations in your code, you can run: ```sh npm run precommit ``` ## Running tests You can run the test suite using the following commands: ```sh npm test ``` Please ensure that the tests are passing when submitting a pull request. If you're adding new features to 🏁 React Final Form, please include tests. ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: erikras patreon: erikras open_collective: final-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 a single custom sponsorship URL ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ ### Are you submitting a **bug report** or a **feature request**? ### What is the current behavior? ### What is the expected behavior? ### Sandbox Link ### What's your environment? ### Other information ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ ================================================ FILE: .github/workflows/ci.yml ================================================ name: CI on: [push] jobs: lint: name: Lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v2 with: node-version: "22" - name: Prepare env run: yarn install --ignore-scripts --frozen-lockfile - name: Run linter run: yarn start lint prettier: name: Prettier Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v2 with: node-version: "22" - name: Prepare env run: yarn install --ignore-scripts --frozen-lockfile - name: Run prettier run: yarn start prettier test: name: Unit Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v2 with: node-version: "22" - name: Prepare env run: yarn install --ignore-scripts --frozen-lockfile - name: Run unit tests run: yarn start test - name: Run code coverage uses: codecov/codecov-action@v2.1.0 ================================================ FILE: .github/workflows/lock.yml ================================================ name: "Lock Threads" on: schedule: - cron: "0 * * * *" workflow_dispatch: permissions: issues: write pull-requests: write concurrency: group: lock jobs: action: runs-on: ubuntu-latest steps: - uses: dessant/lock-threads@v3 with: issue-inactive-days: "365" issue-lock-reason: "resolved" pr-inactive-days: "365" pr-lock-reason: "resolved" ================================================ FILE: .gitignore ================================================ .vscode *.iml .nyc_output coverage flow-coverage node_modules dist lib es npm-debug.log .DS_Store .yalc yalc.lock ================================================ FILE: .prettierignore ================================================ coverage dist node_modules ================================================ FILE: .prettierrc ================================================ { "trailingComma": "all" } ================================================ FILE: .travis.yml ================================================ sudo: false language: node_js before_install: - npm install -g npm@6.4.0 cache: directories: - node_modules notifications: email: false node_js: - "10" - "12" - "14" script: - npm start validate after_success: - npx codecov branches: only: - main ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Erik Rasmussen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: MIGRATION_V7.md ================================================ # Migration Guide: react-final-form v6 → v7 ## Overview Version 7.0.0 includes a complete TypeScript rewrite (migrated from Flow). While the runtime behavior remains largely unchanged, there are several TypeScript-specific breaking changes you need to be aware of. ## Breaking Changes ### 1. FormState Properties Now Optional In v7.0.0, most FormState boolean properties can be `undefined`: **❌ Before (v6.x):** ```typescript const { dirty, pristine, valid } = formState; if (dirty && !pristine) { // Works fine // ... } ``` **✅ After (v7.0.0):** ```typescript const { dirty, pristine, valid } = formState; if ((dirty ?? false) && !(pristine ?? true)) { // Must handle undefined // ... } ``` **Affected properties:** - `dirty`, `pristine`, `valid`, `invalid` - `dirtySinceLastSubmit`, `modifiedSinceLastSubmit` - `submitFailed`, `submitSucceeded`, `submitting`, `validating` - `hasSubmitErrors`, `hasValidationErrors` **Note:** `values` is still guaranteed to be defined. ### 2. FieldMetaState Type No Longer Exported **❌ Before (v6.x):** ```typescript import { FieldMetaState } from 'react-final-form'; const meta: FieldMetaState = { /* ... */ }; ``` **✅ After (v7.0.0):** ```typescript import { FieldRenderProps } from 'react-final-form'; const meta: FieldRenderProps['meta'] = { /* ... */ }; // Or define it locally: type FieldMetaState = { active?: boolean; data?: Record; dirty?: boolean; // ... etc }; ``` ### 3. AnyObject Type No Longer Exported **❌ Before (v6.x):** ```typescript import { AnyObject } from 'react-final-form'; ``` **✅ After (v7.0.0):** ```typescript // Define locally: type AnyObject = Record; ``` ### 4. UseFieldConfig No Longer Generic **❌ Before (v6.x):** ```typescript const config: UseFieldConfig = { validate: (value) => value ? undefined : 'Required' }; ``` **✅ After (v7.0.0):** ```typescript const config: UseFieldConfig = { validate: (value) => value ? undefined : 'Required' }; ``` ### 5. FormProps No Longer Accepts Arbitrary Props In v6.x, you could pass arbitrary props (like `style`, `className`) directly to `
`. In v7.0.0, this is no longer supported due to stricter TypeScript typing. **❌ Before (v6.x):** ```tsx {/* ... */}
``` **✅ After (v7.0.0):** ```tsx
{({ handleSubmit }) => ( {/* ... */}
)} // Or wrap in a div:
{/* ... */}
``` ## final-form v5.0.0 Changes If you're also upgrading final-form to v5.0.0, be aware of these changes: ### 1. InternalFormState Requires asyncErrors **❌ Before (v4.x):** ```typescript const mockFormState: InternalFormState = { values: {}, // ... }; ``` **✅ After (v5.0.0):** ```typescript const mockFormState: InternalFormState = { values: {}, asyncErrors: {}, // Now required // ... }; ``` ### 2. Mutator Type Signature Changed **❌ Before (v4.x):** ```typescript const mutator: Mutator = (args, state, tools) => { // ... }; ``` **✅ After (v5.0.0):** ```typescript // If you get type errors with existing mutators: const mutator = ((args, state, tools) => { // ... }) as unknown as Mutator; ``` ## Migration Strategy For a medium to large codebase, expect to modify 100+ files. Here's a recommended approach: 1. **Update dependencies:** ```bash npm install react-final-form@^7.0.0 final-form@^5.0.0 ``` 2. **Fix compilation errors in this order:** - Handle optional boolean properties (use `?? false` or `?? true`) - Replace `FieldMetaState` imports with `FieldRenderProps['meta']` - Replace `AnyObject` imports with local type definition - Remove generic from `UseFieldConfig` → `UseFieldConfig` - Fix `
` props (move styling to wrapper or inner ``) 3. **Test thoroughly:** - All form submissions - Validation behavior - Field state management - Meta information display 4. **Update mocks/tests:** - Add `asyncErrors: {}` to InternalFormState mocks - Cast mutators if needed ## Need Help? If you encounter issues during migration: 1. Check the [TypeScript examples](https://github.com/final-form/react-final-form/tree/main/examples/typescript) 2. Review [closed issues](https://github.com/final-form/react-final-form/issues?q=is%3Aissue+typescript) 3. Open a [new issue](https://github.com/final-form/react-final-form/issues/new) with a reproduction ## Benefits of v7.0.0 Despite the migration effort, v7.0.0 brings significant benefits: - **Better TypeScript support** - First-class TypeScript instead of generated types from Flow - **Improved type inference** - Better autocomplete and type checking - **Modern codebase** - Easier for contributors to work with - **Long-term maintainability** - TypeScript ecosystem is more active than Flow --- **Version**: 7.0.0 **Last Updated**: 2026-02-13 ================================================ FILE: README.md ================================================ # 🏁 React Final Form [![React Final Form](banner.png)](https://final-form.org/react) [![Backers on Open Collective](https://opencollective.com/final-form/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/final-form/sponsors/badge.svg)](#sponsors) [![NPM Version](https://img.shields.io/npm/v/react-final-form.svg?style=flat)](https://www.npmjs.com/package/react-final-form) [![NPM Downloads](https://img.shields.io/npm/dm/react-final-form.svg?style=flat)](https://www.npmjs.com/package/react-final-form) [![Build Status](https://travis-ci.org/final-form/react-final-form.svg?branch=master)](https://travis-ci.org/final-form/react-final-form) [![codecov.io](https://codecov.io/gh/final-form/react-final-form/branch/master/graph/badge.svg)](https://codecov.io/gh/final-form/react-final-form) [![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) ✅ Zero dependencies (that affect your bundle size) ✅ Only peer dependencies: React and [🏁 Final Form](https://github.com/final-form/final-form#-final-form) ✅ Opt-in subscriptions - only update on the state you need! ✅ 💥 [**3.0k gzipped**](https://bundlephobia.com/result?p=react-final-form) 💥 --- [](https://www.sencha.com/) ### React Final Form is sponsored by [Sencha](https://www.sencha.com/). Comprehensive JS framework and UI components for building enterprise-grade web apps. --- ## 💬 [Give Feedback on React Final Form](https://goo.gl/forms/dxdfxKNy64DLb99z2) 💬 In the interest of making 🏁 React Final Form the best library it can be, we'd love your thoughts and feedback. [Take a quick survey](https://goo.gl/forms/dxdfxKNy64DLb99z2). --- React Final Form is a thin React wrapper for [Final Form](https://final-form.org), which is a subscriptions-based form state management library that uses the [Observer pattern](https://en.wikipedia.org/wiki/Observer_pattern), so only the components that need updating are re-rendered as the form's state changes. ## [Getting Started](https://final-form.org/docs/react-final-form/getting-started) ## 🔄 Upgrading from v6 to v7? See the [Migration Guide](./MIGRATION_V7.md) for TypeScript-specific breaking changes and how to handle them. ## [Philosophy](https://final-form.org/docs/react-final-form/philosophy) ## [Examples](https://final-form.org/docs/react-final-form/examples) ## [API](https://final-form.org/docs/react-final-form/api) ## [FAQ](https://final-form.org/docs/react-final-form/faq) ================================================ FILE: docs/api/Field.md ================================================ # This documentation is meant to be read on [final-form.org](https://final-form.org/docs/react-final-form/api/Field). Links may not work on Github.com. # `` ```ts import { Field } from 'react-final-form' ``` A component that registers a field with the containing form, subscribes to field state, and injects both field state and callback functions, `onBlur`, `onChange`, and `onFocus` via a render prop. The `` will rerender any time the field state it is subscribed to changes. By default it subscribes to _all_ field state. You can control which field state it subscribes to with the `subscription` prop. ## Props `` accepts [`FieldProps`](../types/FieldProps) and will call the render function with [`FieldRenderProps`](../types/FieldRenderProps). The only two required props are [`name`](../types/FieldProps#name) and one of [`component`](../types/FieldProps#component), [`render`](../types/FieldProps#render), or [`children`](../types/FieldProps#children). ## Basic Usage You need to do three things when using ``: ### 1. Provide a `name` prop The name of the field can be a reference to a "deep" value via [dot-and-bracket syntax](/docs/final-form/field-names), e.g. `'clients[0].address.street'`. ### 2. Provide a way to render the field There are four ways to render a `` component: | Prop | Type | | -------------------- | ---------------------------------- | | `` | `'input' or 'select' or 'textarea'` | | `` | `React.ComponentType` | | `` | `Function` | | `` | `Function` | The only important distinction is that if you pass a component to the `component` prop, it will be rendered with [`React.createElement()`](https://reactjs.org/docs/react-api.html#createelement), resulting in your component actually being in the React node tree, i.e. inspectable in [DevTools](https://github.com/facebook/react-devtools#react-developer-tools-). ### 3. Connect the callbacks to your input If you are using `component="input"` (or `select` or `textarea`), `` will do this step for you. ```tsx ``` But if you are using a custom component or a render prop, you will need to do this yourself. `` makes this as easy as possible by bundling all of the props that your input component needs into one object prop, called `input`, which contains [`name`](../types/FieldRenderProps#inputname), [`onBlur`](../types/FieldRenderProps#inputonblur), [`onChange`](../types/FieldRenderProps#inputonchange), [`onFocus`](../types/FieldRenderProps#inputonfocus), and [`value`](../types/FieldRenderProps#inputvalue). #### HTML Inputs If you're going to be using one of the standard HTML inputs, ``, `