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

124
Views
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 answers
Answer question

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 Report

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 Report

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