Skip to content

Instantly share code, notes, and snippets.

@snamiki1212
Last active June 13, 2023 23:51
Show Gist options
  • Save snamiki1212/88a3515a1a507f3c37b33f8a34f243a3 to your computer and use it in GitHub Desktop.
Save snamiki1212/88a3515a1a507f3c37b33f8a34f243a3 to your computer and use it in GitHub Desktop.
// DECRALER
const ReduxContext = React.createContext(null);
export const ReduxProvider = ({ children }) => {
  const [state, dispatch] = React.useReducer(reducer, initParams);
  return (
    <ReduxContext.Provider value={{ state, dispatch }}>
      {children}
    </ReduxContext.Provider>
  );
};
export const useRedux = () => React.useContext(ReduxContext);
// READY
<ReduxProvider>
  <MyComponents />
</ReduxProvider>
// USE
const {state, dispatch} = useRedux()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment