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

160
Views
React: How important it is to pass the event as parameter in the callback function?
<button 
     className="delete-btn"
     onClick={(event) => props.deleteNote(event, note.id)}
>

The code above is for a button that when clicked, calls a function that is in another component and should pass note.id as its parameter.

To my understanding, when we need to pass a function with extra parameters as props, we need to pass the whole callback function as written above.

However, I tried this version of code that doesn't include the event as the parameter for the callback function, and it seems to still work. Is there an important difference between the code snippets?

<button 
     className="delete-btn"
     onClick={() => props.deleteNote(event, note.id)}
>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It depends on whether you need to do something with the event (like getting data from it or preventing the default action) or not. This is my opinion but i like to always pass it for good measure.

about 4 years ago · Santiago Trujillo 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!