react-persist-hook
Hook for persisting and rehydrating state in React app
Last updated 6 months ago by szlezak .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-persist-hook 
SYNC missed versions from official npm registry.

React Persist Hook

Hook for persisting and rehydrating state in the React app.

Installation

npm install react-persist-hook

or

yarn add react-persist-hook

Usage

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

License

MIT

Current Tags

  • 1.0.7                                ...           latest (6 months ago)

8 Versions

  • 1.0.7                                ...           6 months ago
  • 1.0.6                                ...           6 months ago
  • 1.0.5                                ...           7 months ago
  • 1.0.4                                ...           7 months ago
  • 1.0.3                                ...           7 months ago
  • 1.0.2                                ...           7 months ago
  • 1.0.1                                ...           7 months ago
  • 1.0.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |