1.0.7 • Published 3 years ago

react-persist-context v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

react-persist-context

Simple React state management library built on top of useContext and useReducer with data persistence.

Installation

npm i react-persist-context

Usage

Initialization

Wrap the main entry file with PersistentContextProvider.

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

The store is an object value consisting of state and reducer (the same basic structure from 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 (...)
}

Persistence

The data persistence uses cookies and by default in session.

License

ISC

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago