Skip to content

Instantly share code, notes, and snippets.

@mikekoro
Created May 9, 2020 05:40
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 mikekoro/6ba5e8550e7c9cad2284738c2098ff16 to your computer and use it in GitHub Desktop.
Save mikekoro/6ba5e8550e7c9cad2284738c2098ff16 to your computer and use it in GitHub Desktop.
// 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