resolvers: ZodResolver error: "Expected number, received string"
The zodResolver example does not work as there is alway the following error.
{
"age":{
"message":"Expected number, received string",
"type":"invalid_type"
}
}
Here is a code sandbox to reproduce the error: https://codesandbox.io/s/react-hook-form-zod-resolver-example-forked-0p8rt?file=/src/App.js
Thanks for your reply/help.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 19 (3 by maintainers)
Coerce primitive values with Zod. Full example
After a bit of digging around, i’ve discovered that the following achieves what i was looking for:
@lailo If you won’t update to
zod@beta
v2 and don’t need to transform the value in number, you can do the following:Please see coercion: https://github.com/colinhacks/zod#coercion-for-primitives
Hi @lailo , this is “normal” when using an input
type="number"
,e.target.value
is a string, to have a number, you should usee.target.valueAsNumber
. You can find an answer here https://github.com/react-hook-form/resolvers/issues/62.You’re right, the example does not work as expected, we have to update it 😃
This worked perfect for me, many thanks @omgismartinez
works, perfectly!
You saved my time. Thanks!