Formik Persist
Persist and rehydrate a Formik form.
npm install formik-persist --save
Basic Usage
Just import the <Persist >
component and put it inside any Formik form. It renders null
!
const Signup = <div> <h1>My Cool Persisted Form</h1> <Formik onSubmit= console initialValues= firstName: '' lastName: '' email: '' render= <Form className="whatever"> <Field name="firstName" placeholder="First Name" /> <Field name="lastName" placeholder="Last Name" /> <Field name="email" type="email" placeholder="Email Address" /> <button type="submit">Submit</button> <Persist name="signup-form" /> </Form> /> </div>;
Props
Only two props!
name: string
: LocalStorage key to save form state todebounce:? number
: Default is300
. Number of ms to debounce the function that saves form state.
Author
- Jared Palmer @jaredpalmer
Todo
- Alternative storages (localForage, sessionStorage)
- Support AsyncStorage for React Native