Simple React state management library built on top of useContext and useReducer with data persistence using session storage.
npm install react-context-session-persist---
React state management library built on top of useContext and useReducer with data persistence using session storage.
```
yarn add react-context-session-persist
---
#### Initialization
Wrap the main entry file with PersistentContextProvider.
``
import { PersistentContextProvider } from 'react-persist-context'
// code before returning...
return (
)
Declare your store with state and reducer as same as redux
``
const store = {
state: yourInitialState
reducer: yourReducer
}
#### Accessing persisted context
After initializing your provider, you can now access the persisted context using usePersistedContext which returns { state, dispatch }
`
// component who is accessing
import { usePersistedContext } from 'react-persist-context'
const CompononentWhoIsUsing = () => {
const { state, dispatch } = usePersistedContext()
/ rest of the code/
return (...)
}
``