Created
December 2, 2019 12:52
-
-
Save felipekm/283efc6d7a75e8933fbeb33cb075a6e8 to your computer and use it in GitHub Desktop.
The simplest React Hook
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
import React, { useState } from 'react'; | |
function ComponentExample() { | |
const [ state, setState ] = useState({ counter:0 }); | |
const addToCounter = () => { | |
const newCounterValue = state.counter + 1; | |
setState({ counter: newCounterValue }); | |
} | |
return ( | |
<div> | |
<p>You clicked {state.counter} times</p> | |
<button onClick={addToCounter}> | |
Click me | |
</button> | |
</div> | |
); | |
} | |
export default ComponentExample; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment