Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
react-hook-form: handleSubmit is not a function

I want to use react-hook-form to handle input from the user. React gives me an error saying "handleSubmit is not a function". Any help would be appreciated.

My code is as followed (react-hook-form 7.13.0)

import { useForm } from "react-hook-form";
import axios from "axios";
import styled from "styled-components";

const Style = styled.div`
    .form {
        width: 200px;
        display: flex;
        flex-direction: column;
    }
`;

const Add = (props) => {
    const { register , handleSubmit } = useForm();

    const onSubmit = (e, data) => {
        e.preventDefault();
        console.log(data);
        addReview(data);
    }

    const addReview = (data) => {
        axios.POST("http://localhost:3000/reviews", data).then(() => {
            props.setReviews([...props.reviews, {data}])
        })
    }
    return (
        <Style>
            <h3>Add a review</h3>
            <form className="form" onSubmit={handleSubmit(onSubmit)}>
                <input type="text" placeholder="Book Title" ref={register}></input>
                <input type="text" placeholder="Rating" ref={register}></input>
                <input type="text" placeholder="Review" ref={register}></input>
                <input type="submit" placeholder="Review"></input>
             </form>
        </Style>
    )
};

export default Add;
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Can you please try this...

const Add = (props) => {
  const { register, handleSubmit } = useForm();

  const onSubmit = (data) => {
    console.log(data);
    addReview(data);
  };

  const addReview = (data) => {
    axios.POST("http://localhost:3000/reviews", data).then(() => {
      props.setReviews([...props.reviews, { data }]);
    });
  };
  return (
    <Style>
      <h3>Add a review</h3>
      <form className="form" onSubmit={handleSubmit(onSubmit)}>
        <input
          type="text"
          placeholder="Book Title"
          {...register("bookTitle")}
        ></input>
        <input type="text" placeholder="Rating" {...register("rating")}></input>
        <input type="text" placeholder="Review" {...register("review")}></input>
        <input type="submit" placeholder="Review"></input>
      </form>
    </Style>
  );
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

Pass this for every input with the name in order to register:

{...register("rating")}

Reference: https://react-hook-form.com/api/useform/register

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have a typo.

This is what you have currently:

<form className="form" onSubmit={handleSubmit(onSubmit)}>

You call handleSubmit(onSubmit) but I'm guessing you are trying to use onSubmit as a handler. Replace the line above with this:

<form className="form" onSubmit={onSubmit}>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda