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

172
Views
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
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!