1 const [username, userInput] = useInput({ type: "text" });
2 const [password, passwordInput] = useInput({ type: "text" });
3
4 return <>
5 {userInput} -> {username} <br />
6 {passwordInput} -> {password}
7 </>;
8
1 function useInput({ type /*...*/ }) {
2 const [value, setValue] = useState("");
3 const input = <input value={value} onChange={e => setValue(e.target.value)} type={type} />;
4 return [value, input];
5 }
6