Skip to content

useFormContext type error #9991

Answered by IronCub3
IronCub3 asked this question in Q&A
Feb 23, 2023 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

I've found my logical error!
The error was that I was using the errors in the formState and not the fieldState when I've defined my custom element, this way the react fragment is no more needed. The new code is:

import { Controller, useFormContext } from "react-hook-form";
import {
  TextField,
  TextFieldProps,
} from "@mui/material";
import React from "react";

interface FormSelectPropsT {
  name: string;
  label: string;
}

const RhfTextFieldMui: React.FC<FormSelectPropsT & TextFieldProps> = ({
  name,
  label,
  ...selectProps
}: FormSelectPropsT) => {

  const {
    control,
  } = useFormContext();

  return (
    <Controller
      name={name}
      control={control}
      render={({

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@IronCub3
Comment options

Comment options

You must be logged in to vote
2 replies
@IronCub3
Comment options

@IronCub3
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by IronCub3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants