Skip to content

Instantly share code, notes, and snippets.

@mbjelac
Last active March 1, 2019 08:35
Show Gist options
  • Select an option

  • Save mbjelac/66350b29e7a2e3371a2ae512214d854a to your computer and use it in GitHub Desktop.

Select an option

Save mbjelac/66350b29e7a2e3371a2ae512214d854a to your computer and use it in GitHub Desktop.
// 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>
)
}
}
//-----------
@mbjelac
Copy link
Copy Markdown
Author

mbjelac commented Mar 1, 2019

used in this article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment