-
-
Save rishichawda/d3ba7b0e4ae70052bf7ce4693fe3822e to your computer and use it in GitHub Desktop.
Initial redux.js file - Managing Application state without Redux
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
import React from "react"; | |
export const useGlobalState = (initialState = {}, reducer) => { | |
let init; | |
let appState = {}; | |
if (typeof initialState === "function") { | |
init = initialState; | |
} else { | |
appState = initialState; | |
} | |
const [state, dispatch] = React.useReducer( | |
reducer, | |
appState, | |
init | |
); | |
return { | |
...state, dispatch | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment