This hook aims to solve the issue of keeping values from forms in a useState
react state.
If you represent your form values in an object, then updating this object can be repetitive and fiddly, especially if you have multiple forms in your app.
Installation
npm install --save use-form-data
or
yarn add use-form-data
Usage
import useFormData from 'use-form-data'; const formData setFormData = ; return <form> <input ="text" = = /> <input ="email" = = /> <input ="password" = = /> </form>;
If you want to completely overwrite the value of formData
then pass true
as the third parameter to setFormData
const formData setFormData = ;// at this point formData = {name: 'Bob', password: 'PaSsWoRd'} <button =>Press me</button> // after clicking the button, formData will be {username: 'Alice', password: 'banana'}