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. |
|
Any updates on this? |
|
Please add this. |
|
Thanks for the library, but is there any updates/workarounds? |
|
up ! pls |
|
Any update on this? I really need this and i'd prefer not to use yup. |
|
This is a must have in my opinion! |
|
I would love to have this! |
|
Surprised this hasn't been added |
|
Up! Please 🙏 |
|
Guys. I had the same issue. where my schema is: @tfazekas @brianMxBm @landorid And it worked! |
|
Up! |
This comment was marked as spam.
This comment was marked as spam.
|
Zod should support context just like Yup |
|
Have any progress? |
|
Apparently no solution since January 2024 .... |
|
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. |

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:
All reactions