Updating and consuming our state
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
This comment has been minimized.
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