React Hook Form validation not working with custom components
asked 4 days ago
0
0
I'm building a form using React Hook Form with Zod validation, but I'm having trouble getting validation errors to display in my custom input components.
Current Setup
Here's my form setup with React Hook Form:
Custom Input Component
Zod Schema
The Problem
-
Form submission is blocked correctly when validation fails
-
form.formState.errors
contains the error messages -
But
<FormMessage />
doesn't display anything -
No error styling is applied to the inputs
What I've Tried
-
Used
useFormContext()
instead of passing control as prop -
Tried
<FormMessage />
vs<FormMessage>{error?.message}</FormMessage>
-
Checked that form provider wraps the component properly
-
Verified schema validation works independently
Expected Behavior
When validation fails, I expect to see error messages below each input field and error styling on the input borders.
Environment
-
React 18.2.0
-
React Hook Form 7.45.0
-
Zod 3.22.0
-
@hookform/resolvers 3.1.0
Has anyone encountered this issue with custom components and React Hook Form? Any help would be appreciated!
0 Answers
Filters
No answers found
It seems there are no answers yet. Be the first to answer a question.