formhero/examples/custom.tsx

35 lines
600 B
TypeScript
Raw Normal View History

2019-09-28 15:20:56 +00:00
import React from 'react'
import ReactDOM from 'react-dom'
import { useForm } from '../dist'
const Index: React.FC = () => {
const { auto, form, errors } = useForm({
awesome: true,
})
return (
<form onSubmit={e => {
e.preventDefault()
console.log(form)
}}>
<h1>Custom</h1>
<label>
<input type="checkbox" {...auto('awesome', {
setter: 'checked',
getter: 'onChange',
extractor: (e) => e.target.checked
})} />
Is it awesome?
</label>
<input type="submit" />
</form>
)
}
ReactDOM.render(<Index />, document.getElementById('custom'))