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

125
Vistas
React.js event with arrow function vs without any () function

hello i am wondering why only normal functions like below works and arrow functions do not.

const Form = () =>{

    const [text, setText] = useState("");

    const handle=(e)=>{
       setText(e.target.value);
    }
    const alertText = (e) =>{
       console.log(text);
       alert(text);
    }

    return(
       <>
           <input onChange={handle}></input>
           <button onClick={alertText}>submit</button>
           <h1>{text}</h1>   
       </>
    )}

using arrow functions like <input onChange={()=>handle}> doesn't work at all and I have no idea what the difference between of them.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Well, that's because if you use an arrow function on the element you have to call it like this:

<input onChange={(e)=>handle(e)}>
about 4 years ago · Juan Pablo Isaza Denunciar

0

component expects onChange as a function, that function will be called when the user changes the value of the input.

NOTE: It's syntactically correct but the handle function will not execute.

When you do

<input onChange={handle}></input>
// it's equivalent to
<input onChange={(e)=>{ setText(e.target.value); }}></input>

But when you do

<input onChange={()=>handle}></input>
// it's equivalent to
<input onChange={(e) => ()=>{ setText(e.target.value);}}></input>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do:

 <input onChange={(e)=>handle(e)}>

You are not passing the event into the handle function

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