Created
April 17, 2021 14:24
-
-
Save youkoucoding/786952e5b4c1e0b2c1579db61317a83e to your computer and use it in GitHub Desktop.
set state using
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
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