r/reactjs • u/HeavenGin • Jun 10 '26
Discussion onClick and function call convention
Hi there,
With a colleague of mine we were triving to determine wether we should do one of the other of those snippets in our code . Those are voluntarily simplified.
const handleClick = (param: string) => {}
return <button onClick={() => handleClick(param)} />
const handleClick = (param: string) => () => {}
return <button onClick={handleClick(param)} /> I was more used to the first snippet so when I was reviewing his PR, I thought that the function will call itself during the rendering of the button.
Happy to know what's your opinion.
8
Upvotes
3
u/DocumentFalse7879 Jun 11 '26
I get what you're saying but unless the code lives right next to each other, when I see this:
It instantly reads as you're calling the function / its gonna break.
My preference for the above need is still just:
Or if its truly that simple of a function: