Is there any way to access context provided by react-hook-form inside zod's superRefine?
#11403
Replies: 18 comments 7 replies
-
|
Hi, @DiegoSaturno ! Any progress on this question? I'm trying to figure out how to do this correctly with Zod. Because in Yup library, for example, this approach is really common and easy to use. |
Beta Was this translation helpful? Give feedback.
-
|
Any updates on this? |
Beta Was this translation helpful? Give feedback.
-
|
Please add this. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the library, but is there any updates/workarounds? |
Beta Was this translation helpful? Give feedback.
-
|
up ! pls |
Beta Was this translation helpful? Give feedback.
-
|
Any update on this? I really need this and i'd prefer not to use yup. |
Beta Was this translation helpful? Give feedback.
-
|
This is a must have in my opinion! |
Beta Was this translation helpful? Give feedback.
-
|
I would love to have this! |
Beta Was this translation helpful? Give feedback.
-
|
Surprised this hasn't been added |
Beta Was this translation helpful? Give feedback.
-
|
Up! Please 🙏 |
Beta Was this translation helpful? Give feedback.
-
|
Guys. I had the same issue. where my schema is: @tfazekas @brianMxBm @landorid And it worked! |
Beta Was this translation helpful? Give feedback.
-
|
@bluebill1049 any plan to add this? |
Beta Was this translation helpful? Give feedback.
-
|
Up! |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
Zod should support context just like Yup |
Beta Was this translation helpful? Give feedback.
-
|
Have any progress? |
Beta Was this translation helpful? Give feedback.
-
|
Apparently no solution since January 2024 .... |
Beta Was this translation helpful? Give feedback.
-
|
colinhacks/zod#4745 (comment) is a response by the maintainer of Zod which states that "It's very unlikely any context mechanism gets added [to Zod]". The suggested workaround is: function makeSchema(ctx: object) {
return z.object({
/// define
})
}
type Output = z.infer<ReturnType<typeof makeSchema>>;As long as the schema isn't dynamic and has a consistent input/output types (it only uses the context within a refinement), this is a decent approach. Unless Zod changes to support external context, I don't think there's anything that react-hook-form can do to support this use-case. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context:
I have a validation on my form that depends on a calculated value, provided by an xstate selector. I tried to access it through zod's
RefinementContextbut wasn't able to do so.Is there any way I can get this value inside
superRefine? If not, is there any way I can write a custom resolver and merge it withzodResolver?The code looks like this:
Beta Was this translation helpful? Give feedback.
All reactions