use-controlled-form
v0.0.17
Published
Create simple controlled React forms, using hooks, without all the fluff!
Downloads
13
Maintainers
Readme
use-controlled-form
Create simple controlled React forms, using hooks ⚓, without all the fluff!
🚨 use-controlled-form
requires React >= 16.8 🚨
Installation
Install with NPM:
npm i use-controlled-form
Install with Yarn:
yarn add use-controlled-form
Basic Usage
import useForm from "use-controlled-form";
function LoginForm() {
const { fields, onSubmit } = useForm({
initialValues: {
username: "",
password: ""
},
onSubmit: values => {
console.log(values); // { username: 'foo', password: 'bar' }
}
});
return (
<form onSubmit={onSubmit}>
<input {...fields.username} />
<input type="password" {...fields.password} />
<button type="submit">Login</button>
</form>
);
}
export default LoginForm;