For more control and type safety, you can use the standard useForm hook from react-hook-form and pass the control object to the individual element components. This allows you to integrate the elements into your own <form> tag and manage submission manually via handleSubmit.
import {useForm} from 'react-hook-form'
import {TextFieldElement, AutocompleteElement, CheckboxElement, Button} from 'react-hook-form-mui'
import {Stack} from '@mui/material'
function Form() {
const {control, handleSubmit} = useForm({
defaultValues: {
name: '',
auto: '',
check: false
},
})
const options = [
{id: 'one', label: 'One'},
{id: 'two', label: 'Two'},
{id: 'three', label: 'Three'},
]
return (
<form onSubmit={handleSubmit((data) => console.log(data))} noValidate>
<Stack spacing={2}>
<TextFieldElement
name={'name'}
label={'Name'}
control={control}
required
fullWidth
/>
<AutocompleteElement
name={'auto'}
label={'Autocomplete'}
control={control}
options={options}
/>
<CheckboxElement name={'check'} label={'Check'} control={control} />
<Button type={'submit'} color={'primary'}>
Submit
</Button>
</Stack>
</form>
)
}
}