@nehring/react-useform
v0.0.1
Published
Form helper using react hook
Downloads
1
Readme
WORKING!
import React from 'react'
import useForm from 'react-useform'
const initialValues = {
email: 'olar',
password: '',
}
function validate(values) {
const errors = {}
if (!values.email) errors.email = 'email error'
return errors
}
function TextField({ input, error, meta, label, inputProps = {} }) {
return (
<div className="field">
<label htmlFor={input.id}>{label}</label>
<input {...inputProps} {...input} />
{error && <span>{error}</span>}
</div>
)
}
function App() {
const { fields, onSubmit } = useForm({
initialValues,
validate,
handleSubmit: console.warn,
})
return (
<form onSubmit={onSubmit}>
<TextField label="Email" {...fields.email} />
<TextField label="pass" {...fields.password} />
<button type="submit">submit</button>
</form>
)
}