@usereact/use-form-fields
v1.0.0
Published
> react hook to simplify forms
Downloads
1
Readme
@usereact/use-form-fields
react hook to simplify forms
Install
npm install --save @usereact/use-form-fields
Usage
import React from 'react'
import useFormFields from '@usereact/use-form-fields'
const initialValues = {
name: '',
email: '',
message: '',
}
function Example() {
const { values, fields } = useFormFields(initialValues)
const handleSubmit = e => {
e.preventDefault();
console.log('values: ', values)
}
return (
<form onSubmit={handleSubmit}>
<label>Name: </label>
<input type="text" {...fields.name} />
<label>Email: </label>
<input type="email" {...fields.email} />
<label>Message: </label>
<textarea {...fields.message} />
<button type="submit">Submit</button>
</form>
)
}
License
MIT © JuHwon