Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
How to change value of min validation after reponse from API in Formik Validation schema?

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")
      })
  })

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!