Reputation: 41
I copied/paste the first example of the React Hook Forms from NB 3.0 and getting this error. TypeError: errors is not an Object. (evaluating '"firstName" in errors'). Any idea why?
Upvotes: 0
Views: 796
Reputation: 151
The example provided here Native Base V3 React-Hook_forms does not use the controller correctly to get onChangeText state and to catch errors for the value, to fix this change the following;
Change the line: const { control, handleSubmit, errors } = useForm();
to const { control, handleSubmit, watch, formState: { errors } } = useForm();
In the Controller change render={({ onChange, onBlur, value })
to render={({ field: { onChange, onBlur, value } })
In the Input component change onChangeText={(val) => onChange(val)}
to onChangeText={onChange}
Reference is from the integration example on the React-Hook-Form website here: React Hook Form with React Native
Upvotes: 6