Skip to content

Instantly share code, notes, and snippets.

@hosseinmd
Last active January 10, 2020 13:50
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 hosseinmd/4e29cb74e5d506dad130c50daea7271b to your computer and use it in GitHub Desktop.
Save hosseinmd/4e29cb74e5d506dad130c50daea7271b to your computer and use it in GitHub Desktop.
import React from "react";
import { Store } from "./store";
import Count from "./Count";
//don't connect to store
const App = () => {
const {actions} = Store
return (
<div>
<Count />
<button
type="button"
onClick={() => actions.increase()}
>
+1 to counter
</button>
<button
type="button"
onClick={() => actions.decrease()}
>
-1 to counter
</button>
</div>
);
};
export default App
import React from "react";
import { useGlobal } from "./store";
// connected to store
const Count = () => {
const [state, actions] = useGlobal(["counter"]);
return (
<p>
counter:
{state.counter}
</p>
);
};
export default Count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment