Skip to content

Instantly share code, notes, and snippets.

@venil7
Created November 30, 2018 13:24
Show Gist options
  • Save venil7/75a7a51c063c47781cf67877290e2aeb to your computer and use it in GitHub Desktop.
Save venil7/75a7a51c063c47781cf67877290e2aeb to your computer and use it in GitHub Desktop.
Use redux middle with React hooks
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