▲ 3 r/reactjs
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.
u/HeavenGin — 11 hours ago