Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda