I found this question but it doesn't answer my specific case, because the answers are old, don't answer all my questions in this post and in that case they only pass the event variable to the function, but in my case I might want to pass a different type of value, like a string: React performance: anonymous function vs named function vs method
In React, on a function component, let's say I have a button:
return <button>Click me</button>
I want to add an onClick event to it, but instead of passing the mouse event to the function, I want to send other kinds of data. What's the correct (or even better, the most performant) pattern?
The use case would be a grid with hundreds of cells, and every cell has an onClick event. I guess that option b would be better because we're only passing a reference, right? Does modern React have some kind of optimizations for this use case?
a)
const handleClick = (value) => console.log(value);
return <button onClick={() => handleClick('hello')}>Click me</button>
b)
const handleClick = (value) => () => console.log(value);
return <button onClick={handleClick('hello')}>Click me</button>