🐊Putout plugin adds ability to migrate to latest version of React Hook Form. Not bundled.
npm i putout @putout/plugin-react-hook-form -D
Add .putout.json
with:
{
"plugins": [
"react-hook-form"
]
}
Here is list of rules:
{
"rules": {
"react-hook-form/v7-apply-form-state": "on",
"react-hook-form/v6-apply-clear-errors": "on",
"react-hook-form/v6-convert-as-to-render": "on",
"react-hook-form/v6-convert-form-context-to-form-provider": "on",
"react-hook-form/v6-convert-trigger-validation-to-trigger": "on",
"react-hook-form/v5-remove-value-from-control": "on"
}
}
errors
located in formState
in v7
.
Check out in 🐊Putout Editor.
import {useForm} from 'react-hook-form';
const {errors} = useForm();
import {useForm} from 'react-hook-form';
const {formState} = useForm();
const {errors} = formState;
clearError
was renamed to clearErrors
in v6
.
Check out in 🐊Putout Editor.
const {
register,
setError,
clearError,
errors,
} = useForm<{}>;
const {
register,
setError,
clearErrors,
errors,
} = useForm<{}>;
Control
has no as
, it uses render
starting from v6
.
Check out in 🐊Putout Editor.
const a = <Controller
as={CustomInput}
valueName="textValue"
onChangeName="onTextChange"
control={control}
name="test"
/>;
const a = <Controller
render={({onChange, onBlur, value}) => <CustomInput onTextChange={onChange} onBlur={onBlur} textValue={value} />}
control={control}
name="test" />;
FormContext
was renamed to FormProvider
starting from v6
.
Check out in 🐊Putout Editor.
import {FormContext} from 'react-hook-form';
export default () => <FormContext></FormContext>
;
import {FormProvider} from 'react-hook-form';
export default () => <FormProvider></FormProvider>
;
triggerValidation
was renamed no trigger
, starting from v6
.
Check out in 🐊Putout Editor.
import {useForm} from 'react-hook-form';
const {
register,
triggerValidation,
errors,
} = useForm();
triggerValidation();
import {useForm} from 'react-hook-form';
const {
register,
trigger,
errors,
} = useForm();
trigger();
Return value of control
attribute function no longer has value
property in v5
.
Check out in 🐊Putout Editor.
import {TextInput} from 'react-native';
const a = <Controller
as={<TextInput style={{borderWidth: 2, borderColor: 'black'}} />}
name="text"
control={(args) => ({
value: args[0].nativeEvent.text,
})}
onChange={onChange}
/>;
import {TextInput} from 'react-native';
const a = <Controller
as={<TextInput style={{borderWidth: 2, borderColor: 'black'}} />}
name="text"
control={(args) => args[0].nativeEvent.text}
onChange={onChange}
/>;
MIT