-
-
Save rishichawda/853c751bb5c27eee52b0f504c39ac7e2 to your computer and use it in GitHub Desktop.
App.js with useGlobalState - 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"; | |
import { useGlobalState } from "./redux"; | |
import reducer from "./reducer"; | |
import ChildComponent from "./ChildComponent"; | |
import "./App.scss"; | |
const App = () => { | |
const globalState = useGlobalState({ count: 0 }, reducer); | |
return ( | |
<> | |
<div className="app"> | |
<h2>Welcome to React!</h2> | |
<h2>{globalState.count}</h2> | |
<button type="button" onClick={() => globalState.dispatch({ type: "increment" })}> | |
Click me to plus one! | |
</button> | |
</div> | |
<ChildComponent /> | |
</> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment