@nehring/react-useform
0.0.1 • Public • Published
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>
)
}
Package Sidebar
Install
npm i @nehring/react-useform
Weekly Downloads