Skip to content

Instantly share code, notes, and snippets.

@Uzwername
Last active August 28, 2020 11:12
Show Gist options
  • Save Uzwername/2b3b1c181f809cc79432568e0a1eed21 to your computer and use it in GitHub Desktop.
Save Uzwername/2b3b1c181f809cc79432568e0a1eed21 to your computer and use it in GitHub Desktop.
Functions vs. Components - App.js
const App = () => {
const [total, setTotal] = useState(0);
const incrementTotal = () => setTotal(currentTotal => currentTotal + 1);
return (
<div className="App">
<div>
<h4>Total Clicks: {total}</h4>
</div>
<div className="CountersContainer">
<Counter onClick={incrementTotal} />
<Counter onClick={incrementTotal} />
<Counter onClick={incrementTotal} />
</div>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment