Skip to content

Instantly share code, notes, and snippets.

@felipekm
Created December 2, 2019 12:52
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 felipekm/283efc6d7a75e8933fbeb33cb075a6e8 to your computer and use it in GitHub Desktop.
Save felipekm/283efc6d7a75e8933fbeb33cb075a6e8 to your computer and use it in GitHub Desktop.
The simplest React Hook
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