admin管理员组文章数量:1353001
Is it possible to add custom keys to the Zod ctx.addIssue that can then be retrieved in the Form.formState.errors from react-hook-form
?
For example here I want to add "foo" as a custom entry:
MyConfig.superRefine((data, ctx) => {
ctx.addIssue({
...issue,
code: z.ZodIssueCode.custom,
params: {
context: "foo",
},
message: `${issue.message} | ${Module.label}`,
path: [...pathPrefix, index],
});
});
And then be able to retrieve that in the corresponding react-hook-form
errors. But when I log the errors it seems like the whole params (or any other key I add for that matter) are gone:
console.log(Form.formState.errors);
// => {
"some": {
"path": [
{
"message": "Some error message",
"type": "custom",
"ref": {
"name": "config.some.path.0",
"value": {
...the value
}
}
}
]
},
}
Thank you!
本文标签: reactjsCustom error keys in reacthookform with zod (superRefine amp ctxaddIssue)Stack Overflow
版权声明:本文标题:reactjs - Custom error keys in react-hook-form with zod (superRefine & ctx.addIssue) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743915570a2561150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论