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

279
Views
I want to reset value to initial value formik

I am getting some value from the backend and I am string in state and using throw formik what my task is I create reset onClick so like if I edit something but I don't want to use it then if I click on reset onClick then it set to initial value and I create one state and update that in onClick but if I am checking in the console I am getting initial value but in UI nothing happening see image for reference

const [formValue, setFormValue] = useState(null);
  useEffect(() => {
    fetchSearchRule(rules);
  }, []);
  let initialValues = {
    exactNameMatch: rules.exactNameMatch,
    partialNameMatch: rules.partialNameMatch,
    partialNameMatchThreshold: rules.partialNameMatchThreshold,
    exactDOBMatch: rules.exactDOBMatch,
    partialDOBMatch: rules.partialDOBMatch,
    partialDOBMatchThreshold: rules.partialDOBMatchThreshold,
    countryMatch: rules.countryMatch,
    zipCodeMatch: rules.zipCodeMatch,
    completeAddressMatch: rules.completeAddressMatch,
    partialAddressMatchThreshold: 50,
    allSanctionsList:checked,
    FormChangeCount: 0,
  };

  const ruleForm = useFormik({
    initialValues,
    enableReinitialize: true,
    onSubmit: (values) => {
      updateSearchRules(values);
      setChangeRuleSettings(false);
      ruleForm.values.FormChangeCount = 0;
    },
  });

                <Box>
                  <Typography
                    onClick={() => {setFormValue(initialValues)
                      setChangeRuleSettings(false);
                    }}
                    color="secondary"
                    variant="subtitle2"
                    style={{ cursor: "pointer" }}
                  >
                    Reset Rule
                  </Typography>
                </Box>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I find it a bit difficult to understand what you're asking, but I'll try to answer. If all you want is to reset the entire form when the user clicks on the text Reset Rule, then use Formik's function resetForm:

<Box>
    <Typography
        onClick={ruleForm.resetForm}
        color="secondary"
        variant="subtitle2"
        style={{ cursor: "pointer" }}
    >
    Reset Rule
    </Typography>
</Box>
        

If you want to reset some values in the form but not all, pass in those input names to resetForm():

onClick={()=>{
  ruleForm.resetForm({
    values: {
      partialDOBMatchThreshold: rules.partialDOBMatchThreshold
    }
  })
}}

Also, remove formValue from state, there is no need for it.

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!