Skip to content

Instantly share code, notes, and snippets.

@samsch
Forked from StoneCypher/foo.jsx
Last active May 22, 2017 21:49
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 samsch/b4f2966c9147d89210d51eb90d2687e5 to your computer and use it in GitHub Desktop.
Save samsch/b4f2966c9147d89210d51eb90d2687e5 to your computer and use it in GitHub Desktop.
StoneCypher's external state example, re-written for React latest (15.x)
let counter = 0;
const repaint = () => React.render(<Spinner data={counter}/>, document.body);
const inc = () => { counter += 1, repaint() };
const dec = () => { counter -= 1, repaint() };
const Spinner = ({ counter }) => (
<div>
{counter}
<button value="^" onclick={inc}/>
<button value="v" onclick={dec}/>
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment