add useDispatch hook
This commit is contained in:
parent
7f2201c945
commit
4b98f6f654
@ -21,13 +21,15 @@ export const usePotentReducer = options => {
|
||||
*/
|
||||
export const createStore = options => {
|
||||
const context = createContext(null)
|
||||
const { Consumer } = context
|
||||
const Provider = ({ children }) => {
|
||||
const store = usePotentReducer(options)
|
||||
return React.createElement(context.Provider, { value: store }, children)
|
||||
}
|
||||
const useStore = () => useContext(context)
|
||||
const useSelector = selector => selector(useContext(context)[0])
|
||||
return { Provider, Consumer: context.Consumer, useStore, useSelector }
|
||||
const useDispatch = () => useContext(context)[1]
|
||||
return { Provider, Consumer, useStore, useSelector, useDispatch }
|
||||
}
|
||||
|
||||
/** Turn a reducer definition object to a function
|
||||
|
Loading…
Reference in New Issue
Block a user