Last active
December 10, 2018 17:41
-
-
Save Jahans3/d5de84f02f0a41e98b18401b0e2ad51c to your computer and use it in GitHub Desktop.
Updating and consuming our state
This file contains 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
export default function SomeCount () { | |
return ( | |
<StateConsumer> | |
{({ state, setState }) => ( | |
<> | |
<p> | |
Count: {state.count} | |
</p> | |
<button onClick={() => setState({ count: state.count + 1 })}> | |
+ 1 | |
</button> | |
<button onClick={() => setState({ count: state.count - 1 })}> | |
- 1 | |
</button> | |
</> | |
)} | |
</StateConsumer> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @Jahans3, I've read your article and I just found two little mistakes in your gist:
count
in the setState is not defined;So, updating that:
Cheers