MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Passing Arguments to Event Handlers0%
Study Materials
React.js for BeginnersProgress 0%
1.1Why React and Single-Page Architecture1.2Setting Up Modern React with Vite1.3React Project Directory Structure and Entry Points1.4Virtual DOM and React Render Cycle Explained
5.1Handling Synthetic Events in React5.2Passing Arguments to Event Handlers5.3Handling Click, Change, and Submit Events5.4Preventing Default Browser Behaviors
HomeTutorialsReact.js for BeginnersPassing Arguments to Event Handlers
Handling Click, Change, and Submit Events

Passing Arguments to Event Handlers

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Challenge of Custom Arguments

When attaching an event listener in React, passing just the function name works when no extra arguments are needed:

1// React automatically passes the SyntheticEvent 'e'
2<button onClick={handleClick}>Click</button>

However, in real-world applications, you frequently need to pass custom arguments to your handler—such as an item ID, a user object, or an array index:

1// ❌ WRONG: Executes deleteItem(course.id) immediately on render!
2<button onClick={deleteItem(course.id)}>Delete</button>

Writing deleteItem(course.id) invokes the function during render, triggering premature deletions and potentially infinite re-render loops!

2. Solution 1: Inline Arrow Functions (Standard Modern Pattern)

The most widespread, readable, and idiomatic approach in modern React is wrapping the function call in an inline arrow function:

1// ✅ Correct: The arrow function is executed ONLY when the user clicks
2<button onClick={() => deleteItem(course.id)}>
3 Delete Course
4</button>

Accessing Both Custom Arguments and the Event Object (e):

If your handler also needs access to the event object (e.g. to inspect coordinates or prevent default behavior), declare e in the arrow function parameter list:

1<button onClick={(e) => handleEdit(course.id, e)}>
2 Edit
3</button>

In the handler definition:

1const handleEdit = (id, e) => {
2 e.stopPropagation(); // Stop event bubbling
3 console.log('Editing course ID:', id);
4};

3. Solution 2: Higher-Order Functions (Currying)

In advanced component architectures, you can write a handler that returns another function. This is known as function currying:

1export default function CourseList({ courses }) {
2 // Higher-order function returns an event handler pre-bound with courseId
3 const createDeleteHandler = (courseId) => (e) => {
4 console.log(`Deleting course: ${courseId}`, e.target);
5 };
6 
7 return (
8 <ul>
9 {courses.map((course) => (
10 <li key={course.id}>
11 {course.title}
12 {/* createDeleteHandler returns the actual event handler function */}
13 <button onClick={createDeleteHandler(course.id)}>
14 Delete
15 </button>
16 </li>
17 ))}
18 </ul>
19 );
20}

4. Performance Considerations with Inline Functions

In older React documentation, developers were warned against creating inline arrow functions (() => doSomething()) due to memory allocation concerns.

In modern JavaScript engines (V8, JavaScriptCore) and modern React:

  • Creating small inline functions on render has negligible performance overhead in 99% of applications.
  • You should only optimize inline arrow functions (using useCallback) if passing handlers down to heavily memoized child components (React.memo) that render massive lists.
  • For standard components, prioritize clarity, readability, and maintainability.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What happens if you write <button onClick={handleRemove(item.id)}>Remove</button>?
Question 2
What is the most common and idiomatic way to pass custom arguments to an event handler in React?
Question 3
How can you pass both a custom item ID and the React SyntheticEvent e to a handler?
Question 4
What is a higher-order event handler?
Question 5
Is creating an inline arrow function inside an onClick prop acceptable in modern React?
Next Lesson

Handling Click, Change, and Submit Events

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Handling Synthetic Events in ReactHandling Click, Change, and Submit Events

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext