Last active
November 3, 2018 18:09
-
-
Save jhonnymichel/d5074f9d03bf99f2b8328b685e2897d0 to your computer and use it in GitHub Desktop.
hookstore-snippet 2
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
function StatefulHello() { | |
const [timesClicked, updateTimesClicked] = useState(0); | |
return ( | |
<div> | |
<h1>Hello, component!</h1> | |
<h2>The button inside this component was clicked {timesClicked} times</h2> | |
<button type="button" onClick={() => updateTimesClicked(timesClicked + 1)}> | |
Update | |
</button> | |
</div> | |
); | |
} | |
function AnotherComponent() { | |
/* this would not be the same state from StatefulHello | |
const [ timesClicked, updateTimesClicked] = useState() */ | |
return ( | |
<div> | |
<h1> | |
Hello, this is a second component, with no relation to the one on the | |
top | |
</h1> | |
<h2> | |
And there is no way for it to keep track of how many times the user clicked on the button. | |
</h2> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment