Last active
October 28, 2018 08:37
-
-
Save jackyef/e40b27331eca14207f15250af6c0b221 to your computer and use it in GitHub Desktop.
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'; | |
import ReactDOM from 'react-dom'; | |
const useCounter = () => { | |
const [count, setCount] = useState(0); | |
const onIncrease = () => setCount(count + 1); | |
const onDecrease = () => setCount(count - 1); | |
return [ count, onIncrease, onDecrease ]; | |
}; | |
const App = () => { | |
const [ count, onIncrease, onDecrease ] = useCounter(); | |
return ( | |
<div> | |
<div>Current count: {count}</div> | |
<div> | |
<button onClick={onDecrease}>-</button> | |
<button onClick={onIncrease}>+</button> | |
</div> | |
</div> | |
); | |
}; | |
ReactDOM.render(<App />, document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment