Skip to content
Discussion options

You must be logged in to vote

I finally realized that I can use context which is one of the useForm's Schema validation props. These are the steps that I took to get the code to work in the way I wanted:

Step 1: Passing my variable as context to my yup validation schema

As mentioned with the help of one of the useForm's schema validation props called context, I managed to pass my state to yup schema like below: (code is super simplified)

// My State:
const [contextVariable, setContextVariable] = React.useState();
// useForm settings:
const methods = useForm<Type>({
	defaultValues,
	resolver: yupResolver(validationSchema),
	context: {
		contextVariable, // Pass my variable to yup schema
	},
});

Step2: Update yup version:

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@NotNikita
Comment options

@Melancholism
Comment options

Answer selected by Melancholism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants