I want to change the the min validation value after i receive the response from server , Here is the code
const form =useFormik({
initialValues:{name:'',email:'',price:0},
validationSchema:Yup.object({
'email':Yup.string().required("Email required").email("Invalid email"),
'name':Yup.string().required("Name is required"),
'price':Yup.number().min(0,"Invalid price")
})
})
When page load i will receive new min value from the API
useEffect(()=>{
//API call
},[]);
Now I want new validation where min validation value is 500
form=useFormik({
initialValues:{name:'',email:'',price:0},
validationSchema:Yup.object({
'email':Yup.string().required("Email required").email("Invalid email"),
'name':Yup.string().required("Name is required"),
'price':Yup.number().min(500,"Invalid price")
})
})
How about just create a variable and set the value?
var apiValue = 0;
useEffect(()=>{
//API call
apiValue = returnedApiValue //e.g. 500
},[]);
'price':Yup.number().min(apiValue,"Invalid price")