react-context-session-persist
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

react-context-session-persist


React state management library built on top of useContext and useReducer with data persistence using session storage.

Installation

yarn add react-context-session-persist

Usage


Initialization

Wrap the main entry file with PersistentContextProvider.

import { PersistentContextProvider } from 'react-persist-context'
// code before returning...
return (
    <PersistentContextProvider store={store}>
        <App />
    </PersistentContextProvider>
)

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 (...)
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-context-session-persist

Weekly Downloads

24

Version

1.0.6

License

MIT

Unpacked Size

43.2 kB

Total Files

19

Last publish

Collaborators

  • kenshimi