Last active
March 1, 2019 08:35
-
-
Save mbjelac/66350b29e7a2e3371a2ae512214d854a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // file: num-store.js | |
| // plain JS "store" - one of many possible! | |
| //----------- | |
| export const numberStore = { | |
| count: 0; | |
| } | |
| //----------- | |
| // file: incrementor.js | |
| // a react component changing store data | |
| //----------- | |
| import { numberStore } from "./num-store.js"; | |
| class Incrementor extends React.Component { | |
| constructor(props) {} | |
| render() { | |
| return ( | |
| <div> | |
| <button onClick={() => numberStore.count++}>Increment</button> | |
| </div> | |
| ) | |
| } | |
| } | |
| //----------- | |
| // file: count-display.js | |
| // another react component (far away from Incrementor) displaying store data | |
| //----------- | |
| import { numberStore } from "./num-store.js"; | |
| class CountDisplay extends React.Component { | |
| constructor(props) {} | |
| render() { | |
| return ( | |
| <div> | |
| The count is: | |
| <div>{numberStore.count}</div> | |
| </div> | |
| ) | |
| } | |
| } | |
| //----------- |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
used in this article