Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Last active December 10, 2018 18:24
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 Jahans3/4984b39287ebdb97fa247f8ecf331dcb to your computer and use it in GitHub Desktop.
Save Jahans3/4984b39287ebdb97fa247f8ecf331dcb to your computer and use it in GitHub Desktop.
Dispatching actions
export default function SomeCount () {
return (
<StateConsumer>
{({ state, dispatch }) => (
<>
<p>
Count: {state.count}
</p>
<button onClick={() => dispatch(addOne())}>
+ 1
</button>
<button onClick={() => dispatch(addN(5))}>
+ 5
</button>
<button onClick={() => dispatch(addN(10))}>
+ 10
</button>
</>
)}
</StateConsumer>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment