-
Hi There. I'm having some troubles with let dynamicValue = condition ? 1 : 2
const {
register,
trigger,
control,
handleSubmit,
watch,
formState: { errors },
getValues,
setValue,
reset,
} = useForm({
reValidateMode: "onChange",
resolver: yupResolver(carDetailsSchema, {
context: {
maxMarketValue: dynamicValue,
},
}),
shouldUnregister: true,
}); marketValue: yup
.number()
.min(0)
.when("$maxMarketValue", (maxValue, schema) => {
console.log(maxValue);
return schema.min(0).max(maxValue).required();
}),
```
However when I try to log the maxValue to the console is it undefind? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
not sure why it's not having the context, i can see the source code: https://github.com/react-hook-form/resolvers/blob/master/yup/src/yup.ts#L41-L82 |
Beta Was this translation helpful? Give feedback.
-
As I remember, The current implementation of yup resolver is using |
Beta Was this translation helpful? Give feedback.
-
Hi, does anyone know how to do the same in useForm({
context: {something: "something"},
resolver: zodResolver(mySchema)
) I can't find a way to do it. It seems to work only in |
Beta Was this translation helpful? Give feedback.
@Notaduck @bluebill1049 :
As I remember,
context
will be provided viauseForm({ context: { // Some context props } })
, not from resolver schema options 😄The current implementation of yup resolver is using
Object.assign({}, schemaOptions, { context // this is the context from react-hook-form })
therefore the react-hook-form context always overrides the "context" from schemaOptions.