Skip to content

Instantly share code, notes, and snippets.

@rishichawda
Created May 19, 2019 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rishichawda/d72f29069327409c98f37760da1d36f1 to your computer and use it in GitHub Desktop.
Save rishichawda/d72f29069327409c98f37760da1d36f1 to your computer and use it in GitHub Desktop.
App.js with Provider - Managing Application state without Redux
import React from "react";
import { useGlobalState, Provider } from "./redux";
import reducer from "./reducer";
import ChildComponent from "./ChildComponent";
import "./App.scss";
const App = () => {
const globalState = useGlobalState({ count: 0 }, reducer);
return (
<Provider initialValue={globalState}>
<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 />
</Provider>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment