Created
May 9, 2020 05:40
-
-
Save mikekoro/6ba5e8550e7c9cad2284738c2098ff16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// LoginForm.js | |
import React from 'react'; | |
import { useValue } from './useValue'; | |
export function LoginForm({ handleSubmit }) { | |
const { value, assignValue } = useValue(''); // empty string is the initial value; | |
function handleChange(e) { | |
assignValue(e.target.value); // Fire up our custom hook when the user is typing. | |
} | |
function onSubmit(e) { | |
e.preventDefault(); | |
handleSubmit({ value }); | |
} | |
return ( | |
<form onSubmit={(e) => onSubmit(e)}> | |
<input name="name" type="text" value={value} onChange={(e) => handleChange(e)}/> | |
<button type="submit" >Submit</button> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment