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

501
Views
How to submit request with formik and axios

I want to post some data with Axios and I'm using formik but as formik doesn't need an external state for tracking the input fields I don't know what to pass in the payload of Axios post request


const Form = () => {

  const submitHandler = (e) => {
    e.preventDefault();
    axios
      .post("http://127.0.0.1:8000/todo/todos/", {
       // i dont know what to put here, before i use formik it was like this 
      //state,})
  };
  return (
    <Formik
      initialValues={{
        title: "",
        description: "",
      }}
      validationSchema={validate}
    >
      {(formik) => (
        console.log(formik.values),
        (
          <StyledForm onSubmit={submitHandler}>
            <div>
              <div>
                <Input
                  name="title"
                  type="text"
                />
              </div>
              <div>
                <Textarea
                  type={"text"}
                  name="description"
                  as="textarea"
                />
              </div>
            </div>
          </StyledForm>
        )
      )}
    </Formik>
  );
};

export default Form;
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Since Formik handles your values, you should use it as well for submitting your form.

The onSubmit function you pass into Formik has all your needed values.

  const submitHandler = (values) => {
    axios.post("http://127.0.0.1:8000/todo/todos/", values);
    // further handling
  };

  return (
    <Formik
      initialValues={{
        title: "",
        description: "",
      }}
      validationSchema={validate}
      onSubmit={(values) => submitHandler(values)}
    >
  ...
about 4 years ago · Santiago Gelvez 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!