Define Form
Define form offers alternative typescript bindings for final-form. The key difference is that the form data is now a strongly typed object, rather than an any. This make the initialValues config option required.
Installation
yarn add define-form
Usage
import defineForm from 'define-form';
interface FormState {
name: string;
}
type ErrorValue = string;
const form = defineForm<FormState, ErrorValue>({
initialValues: {name: ''},
onSubmit,
validate
})
const unsubscribe = form.subscribe(
formState => {
},
{
dirty: true,
valid: true,
values: true
}
})
const unregisterField = form.registerField(
'username',
fieldState => {
const { blur, change, focus, ...rest } = fieldState
},
{
active: true,
dirty: true,
touched: true,
valid: true,
value: true
}
)
form.submit()
If you like this, you may also want to check out react-define-form
License
MIT