1.0.7 • Published 6 years ago
react-persist-hook v1.0.7
React Persist Hook
Hook for persisting and rehydrating state in the React app.
Installation
npm install react-persist-hookor
yarn add react-persist-hookUsage
import React from 'react'
import usePersist from 'react-persist-hook'
const Signin = () => {
const [signinFormValues, setSigninFormValues] = usePersist('signin-form', 'localStorage', 400);
const { userName, email } = signinFormValues || {};
const initValues = { userName, email };
const handleSubmit = ({ userName, email }) => {
setSigninFormValues({ userName, email });
// rest of the submit method
}
return (
<form onSubmit={handleSubmit}>
{/* rest of the code */}
</form>
)
}Props
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
| key | string | true | Unique storage key | |
| storageType | 'localStorage'|'sessionStorage' | 'localStorage' | false | Storage type name |
| debounceLimit | number | 250 | false | Time in milliseconds to debounce the state persisting |