
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
react-final-form-hooks
Advanced tools
React Hooks to bind to π Final Form's high performance subscription-based form state management engine
β Zero dependencies
β Only peer dependencies: React and π Final Form
β Opt-in subscriptions - only update on the state you need!
β π₯ 1.22 kB gzipped π₯
npm install --save react-final-form-hooks final-form
or
yarn add react-final-form-hooks final-form
π React Final Form Hooks is the leanest possible way to connect π Final Form to React, to acheive subscriptions-based form state management using the Observer pattern.
If performance is your goal, you are recommended to use π React Final Form. Also, that library does many other things for you, like managing checkbox and radio buttons properly. RFFHooks leaves all of that work to you. By default, π React Final Form Hooks subscribes to all changes, but if you want to fine tune your form, you may specify only the form state that you care about for rendering your gorgeous UI.
Here's what it looks like in your code:
import { useForm, useField } from 'react-final-form-hooks'
const MyForm = () => {
const { form, handleSubmit, values, pristine, submitting } = useForm({
onSubmit, // the function to call with your form values upon valid submit
validate // a record-level validation function to check all form values
})
const firstName = useField('firstName', form)
const lastName = useField('lastName', form)
return (
<form onSubmit={handleSubmit}>
<div>
<label>First Name</label>
<input {...firstName.input} placeholder="First Name" />
{firstName.meta.touched && firstName.meta.error && (
<span>{firstName.meta.error}</span>
)}
</div>
<div>
<label>Last Name</label>
<input {...lastName.input} placeholder="Last Name" />
{lastName.meta.touched && lastName.meta.error && (
<span>{lastName.meta.error}</span>
)}
</div>
<button type="submit" disabled={pristine || submitting}>
Submit
</button>
</form>
)
}
Shows how to create fields and attach them to <input/>
elements.
The following can be imported from react-final-form-hooks
.
useField
Returns an object similar to FieldRenderProps
.
useForm
Returns an object similar to FormRenderProps
.
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! π [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
FAQs
React Hooks to bind to π Final Form's high performance subscription-based form state management engine
The npm package react-final-form-hooks receives a total of 3,063 weekly downloads. As such, react-final-form-hooks popularity was classified as popular.
We found that react-final-form-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainerβs token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.