Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2019 08:55
What would you like to do?
import { createContext, useContext, useReducer } from 'react'
import { combineReducers, persistReducer } from 'Reducers/helpers'
import TokenReducer from 'Reducers/Token'
import FeatureReducer from 'Reducers/Feature'
const AppReducer = combineReducers({
token: persistReducer({ key: 'token', storage: localStorage })(TokenReducer),
feature: persistReducer({ key: 'feature', storage: sessionStorage })(FeatureReducer)
const initState = AppReducer()
export const AppReducerContext = createContext()
// for provider
export function useAppReducer () {
return useReducer(AppReducer, initState)
// for consumer
export default function () {
return useContext(AppReducerContext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment