Skip to content

Instantly share code, notes, and snippets.

@youkoucoding
Created April 17, 2021 14:24
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 youkoucoding/786952e5b4c1e0b2c1579db61317a83e to your computer and use it in GitHub Desktop.
Save youkoucoding/786952e5b4c1e0b2c1579db61317a83e to your computer and use it in GitHub Desktop.
set state using
const App = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const setInput = (setter) => (event) => {
setter(event.currentTarget.value);
}
return (
<form>
<input
value={username}
onChange={setInput(setUsername)}
/>
<input
value={username}
onChange={setInput(setPassword)}
/>
</form>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment