0.1.5 • Published 2 years ago

use-persisted v0.1.5

Weekly downloads
280
License
MIT
Repository
github
Last release
2 years ago

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.
0.1.4

2 years ago

0.1.5

2 years ago

0.1.3

3 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago