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

0.1.5 • Public • Published

use-persisted

Persisted versions of useState and useReducer.

  • TypeScript support.
  • Tree-shakeable.
  • Hooks created by the factories have the exact same API and types as useState and useReducer.

createUseStatePersisted

import { createUseStatePersisted } from 'use-persisted'

const useStatePersisted = createUseStatePersisted('localstorage-key')

// In your component.
const [myState, setMyState] = useStatePersisted(myInitialState)

createUseReducerPersisted

import { createUseReducerPersisted } from 'use-persisted'

const useReducerPersisted = createUseReducerPersisted('localstorage-key')

// In your component.
const [myState, dispatch] = useReducerPersisted(myReducer, myInitialState)

Credits

As far as a comparison between this and the listed libs, these are things unique to this package:

  • Provides persisted versions of both state primitives from React.
  • Provides TypeScript types.
  • Is tree-shakeable.
  • Uses tsdx.

Readme

Keywords

none

Package Sidebar

Install

npm i use-persisted

Weekly Downloads

280

Version

0.1.5

License

MIT

Unpacked Size

25.8 kB

Total Files

13

Last publish

Collaborators

  • dylanvann