Created
November 11, 2024 06:15
-
-
Save Soumyarian98/5f2fbbd77b39c9453eb98f06548a95e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useCallback } from "react"; | |
| export const ToDoApp = () => { | |
| const handleTaskClick = useCallback((taskId: string) => { | |
| return (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { | |
| alert(`Task with ID: ${taskId} clicked`); | |
| }; | |
| }, []); | |
| const tasks = [ | |
| { id: "task1", name: "Buy Groceries" }, | |
| { id: "task2", name: "Walk the Dog" }, | |
| { id: "task3", name: "Pay Bills" }, | |
| ]; | |
| return ( | |
| <div> | |
| {tasks.map((task) => ( | |
| // <button key={task.id} onClick={(e) => handleTaskClick(task.id)}> ❌ | |
| <button key={task.id} onClick={handleTaskClick(task.id)}> | |
| {task.name} | |
| </button> | |
| ))} | |
| </div> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment