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

173
Visualizações
How to clear form field - Formik

I have following Formik component.

I would like to clear the field whenever I click 'Clear filters' button. I figured out something like that, but this does not works as I expected. This clear the fields but user is still able to see field value. How should I implement this to clear formik value and user will not see value in form

const Form = () => {

  const handleClearFilters = (resetForm, values) => {
    console.log(values)
    resetForm();
  }

  return (
    <Formik
      initialValues={{
        dog: '',
      }}
      onSubmit={() => {
        // onsubmit functionality
      }}
    >
      {({resetForm, values}) => (
        <FormikForm>
          <Field value={values.dog} name="dog" type="text" as={SearchInput} />
          <Styled.ButtonsWrapper>
            <Styled.Button onClick={() => handleClearFilters(resetForm, values)} kind='secondary'>Clear filters</Styled.Button>
            <Styled.Button type='submit'>Search</Styled.Button>
          </Styled.ButtonsWrapper>
        </FormikForm>
      )}
    </Formik>
  );
};

export default Form;

SearchInput

const SearchInput = ({ name, ...props }) => {
  const [, , helpers] = useField(name);
  const { setValue } = helpers;

  const handleChange = (value: string | null) => {
    setValue(value);
  };

  return (
    <Styled.Wrapper>
      <Styled.Input
        {...props}
        onChange={handleChange}
        placeholder="Search for job name"
        searchType={'primary'}
      />
    </Styled.Wrapper>
  );
};

export default SearchInput;

about 4 years ago · Juan Pablo Isaza
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