Ashwini Kumar
Ashwini Kumar

Reputation: 41

Facing issue with React-hook forms

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

Answers (1)

HagTheDon
HagTheDon

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;

  1. Change the line: const { control, handleSubmit, errors } = useForm(); to const { control, handleSubmit, watch, formState: { errors } } = useForm();

  2. In the Controller change render={({ onChange, onBlur, value }) to render={({ field: { onChange, onBlur, value } })

  3. 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

Related Questions