Skip to content Skip to sidebar Skip to footer

Ref={register} Inside Is Giving Me A Path.split Error

Hi I'm trying to make a form with React and when I put ref={register} inside I get the fo

Solution 1:

The way to register inputs has changed in react-hook-form v7.0.0 (the version you're using).

From the docs,

register method is no longer occurred at ref, instead invoke the function itself and spread the props into the input. The function itself will return the following props: onChange, onBlur, name and ref.

- <input ref={register({ required: true })} name="test" />
+ <input {...register('name', { required: true })} /> 
+ <TextInput {...register('name', { required: true })} />
<input
  className="form-control"
  {...register('text')}
  type="text"
/>

Edit on CodeSandbox

Solution 2:

According to new Version (7.x.x) You have to pass the register Like this

<input {...register('test', { required: true })} />

in 6.x.x it was like

<input inputref={register('test', { required: true })} />

Post a Comment for "Ref={register} Inside Is Giving Me A Path.split Error"