Created
January 9, 2019 06:51
-
-
Save mohanramphp/89c636edd92ed7ddcdc7cf291bfc16a0 to your computer and use it in GitHub Desktop.
Counter example for react hooks
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, Fragment } from 'react'; | |
export const Counter = ({ initialCount }) => { | |
const [count, setCount] = useState(+initialCount); | |
const padding = { | |
marginLeft: '5px', | |
marginRight: '5px', | |
} | |
return ( | |
<Fragment> | |
<button style={padding} className="Pad" onClick={() => setCount(count - 1)}>-</button> | |
{count} | |
<button style={padding} className="Pad" onClick={() => setCount(count + 1)}>+</button> | |
</Fragment> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment