Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Last active October 16, 2020 03:50
Show Gist options
  • Save BrianJenney/68fe9fa08f1fae42bdc357554d0b3053 to your computer and use it in GitHub Desktop.
Save BrianJenney/68fe9fa08f1fae42bdc357554d0b3053 to your computer and use it in GitHub Desktop.
import React from 'react'
import {
Provider,
createStoreHook,
createDispatchHook,
createSelectorHook
} from 'react-redux'
const MyContext = React.createContext(null)
const MyOtherContext = React.createContext(null)
// Export your custom hooks if you wish to use them in other files.
export const useStore = createStoreHook(MyContext)
export const useDispatch = createDispatchHook(MyContext)
export const useSelector = createSelectorHook(MyContext)
export const useOtherStore = createStoreHook(MyContext)
export const useOtherDispatch = createDispatchHook(MyContext)
export const useOtherSelector = createSelectorHook(MyContext)
const myStore = createStore(rootReducer)
const myOtherStore = createStore(rootReducer)
export function MyProvider({ children }) {
return (
<Provider context={MyContext} store={myStore}>
<Provider context={OtherContext} store={myOtherStore}>
{children}
</Provider>
</Provider>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment