Skip to content

Instantly share code, notes, and snippets.

@jhonnymichel
Last active November 3, 2018 18:10
Show Gist options
  • Save jhonnymichel/556fe25b095538ae4c216a437eccf700 to your computer and use it in GitHub Desktop.
Save jhonnymichel/556fe25b095538ae4c216a437eccf700 to your computer and use it in GitHub Desktop.
Hookstore Snippet 1: useState
import React, { useState } from 'react';
function StatefulHello() {
const [timesClicked, updateTimesClicked] = useState(0);
return (
<div>
<h1>Hello, world!</h1>
<h2>The button inside this component was clicked {timesClicked} times</h2>
<button
type="button"
onClick={() => updateTimesClicked(timesClicked + 1)}
>
Update
</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment