Skip to content

Instantly share code, notes, and snippets.

@mohanramphp
Created January 9, 2019 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohanramphp/89c636edd92ed7ddcdc7cf291bfc16a0 to your computer and use it in GitHub Desktop.
Save mohanramphp/89c636edd92ed7ddcdc7cf291bfc16a0 to your computer and use it in GitHub Desktop.
Counter example for react hooks
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