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

1.0.0 • Public • Published

react-native-use-persisted-reducer

A React Hook for React Native who behave exactly like useReducer but persist the state into async storage

Installation

npm i react-native-use-persisted-reducer

Usage

const [state, dispatch] = usePersistedReducer(
  {
    persistKey: 'async storage key used', // a unique key for the async storage entry key (Mandatory)
    whiteList: ['name', 'address'],       // a JS array containing fields to persist (Optional) 
  },
  reducer,
  defaultState
);

Comments

  • Default state is returned when cache is empty
  • If whiteList is omitted then the whole state is persisted in cache
  • Cache is updated each time state is updated
  • additional hydrated field is added to the state once cache has been successfully loaded'

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-use-persisted-reducer

Weekly Downloads

1

Version

1.0.0

License

none

Unpacked Size

8.83 kB

Total Files

11

Last publish

Collaborators

  • mathieusoupart-pxs