formhero/examples/custom.tsx

38 lines
650 B
TypeScript
Raw Permalink Normal View History

2019-09-28 15:20:56 +00:00
import React from 'react'
import { useForm } from '../dist'
2023-01-31 00:26:27 +00:00
import { mount } from './common'
2019-09-28 15:20:56 +00:00
const Index: React.FC = () => {
2023-01-31 00:26:27 +00:00
const { field, form } = useForm({
2019-10-19 06:45:14 +00:00
awesome: true,
})
return (
<form
2023-01-31 00:26:27 +00:00
onSubmit={(e) => {
2019-10-19 06:45:14 +00:00
e.preventDefault()
console.log(form)
}}
>
<h1>Custom</h1>
<label>
<input
type="checkbox"
{...field('awesome', {
setter: 'checked',
getter: 'onChange',
2023-01-31 00:26:27 +00:00
extractor: (e) => e.target.checked,
2019-10-19 06:45:14 +00:00
})}
/>
Is it awesome?
</label>
<input type="submit" />
</form>
)
2019-09-28 15:20:56 +00:00
}
2023-01-31 00:26:27 +00:00
mount(Index)