fireship-io / fireship.io

Build and ship your app faster https://fireship.io
3.54k stars 1.31k forks source link

courses/react-next-firebase/admin-form-validation/ #890

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Form Validation

Add form validation with react-hook-forms

https://fireship.io/courses/react-next-firebase/admin-forms/

JimboTron9000 commented 2 years ago

If you are getting any errors related to useForm or path.split is not a function. A new format is required for the react hooks.

you must create the errors hook from the formstate property and you much also change the way you use the register hook.

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

and

<textarea
          {...register("content", {
            maxLength: { value: 30000, message: "Content is too long!" },
            minLength: { value: 10, message: "Content is too short!" },
            required: { value: true, message: "Content is required" },
          })}
        ></textarea>
mentasuave01 commented 2 years ago

Thanks, @Jimbo Jeff needs to update this