Created
November 30, 2018 13:24
-
-
Save venil7/75a7a51c063c47781cf67877290e2aeb to your computer and use it in GitHub Desktop.
Use redux middle with React hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const useMiddleware = (middlewares, reducer, initState) => { | |
const [state, dispatch] = useReducer(reducer, initState); | |
const getStore = () => ({ dispatch, getState: () => state }); | |
const store = applyMiddleware(...middlewares)(getStore)(); | |
const { dispatch: dispatch_, getState } = store; | |
return [getState(), dispatch_]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment