Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: react-hook-form from version 6.x.x to 7.x.x #29

Open
cabennetts opened this issue Jan 12, 2023 · 1 comment
Open

Error: react-hook-form from version 6.x.x to 7.x.x #29

cabennetts opened this issue Jan 12, 2023 · 1 comment

Comments

@cabennetts
Copy link

cabennetts commented Jan 12, 2023

In /admin/[slug].js

Error 1:

const { register, errors, handleSubmit, formState, reset, watch } = useForm({ defaultValues, mode: 'onChange' });
should be changed to

const { register, handleSubmit, formState, reset, watch, formState: { errors } } = useForm({ defaultValues, mode: 'onChange' });

Error 2:

<textarea
    name="content"
    ref={register({
      maxLength: { value: 20000, message: 'content is too long' },
      minLength: { value: 10, message: 'content is too short' },
      required: { value: true, message: 'content is required' },
    })}
  ></textarea>

should be changed to

<textarea 
          name='content'
          id='content'
          aria-invalid={errors.content ? "true" : "false"}
          {...register('content',
          { maxLength: { value: 20000, message: 'content is too long' },
            minLength: { value: 10, message: 'content is too short' },
            required: { value: true, message: 'content is required' }}
          )} ></textarea>

Error 3:

<input className={styles.checkbox} name="published" type="checkbox" ref={register} />

should be changed to

<input 
    className={styles.checkbox} 
    name="published" 
    type="checkbox" 
    {...register('published')} />
@csanchezwagenbach
Copy link

Essentially, everywhere there is an instance of name = 'someContent' ref={register}, we should instead have name = 'someContent' {...register('someContent', { required: true })}

Two instances on this page, to my eye.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants