This package has been deprecated

Author message:

Project is renamed to react-hook-form-preserved. Please install it instead

use-preserved-form
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

use-preserved-form

This is an extension to react-hook-form that preserves user input in case page was refreshed or form was closed.

Install

npm install react-hook-form

How-to use

Just use usePreservedForm<FormData>('mainForm', options) instead of useForm<FormData>(options). Form imput will be automatically preserved in local-storage and restored after page is refreshed/reopened (technically, on componentDidMount). Parameters:

  • formName - unique name under which form values will be saved in local-storage
  • options - usual options of react-hook-form.

There's also a small example available.

Quickstart

import React from 'react';
import { useForm } from 'react-hook-form';

function App() {
  const { register, handleSubmit, errors, reset } = usePreservedForm('myForm'); // initialise the hook
  const onSubmit = (data) => {
    console.log(data);
    reset(); // most probably you want to reset the form to set empty all inputs
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input name="firstname" ref={register} />
      
      <input name="lastname" ref={register({ required: true })} />
      
      <input type="submit" />
    </form>
  );
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i use-preserved-form

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

5.24 kB

Total Files

8

Last publish

Collaborators

  • shaddix