Here’s a common scenario in React: You’re mapping over an array, and you need each item to call a click handler and with some relevant data.
Here’s an example. I’m iterating over a list of users and passing the userId to delete to the deleteUser function on line 29.
I’m using an arrow function in the click handler. This means every time render runs, a new function is allocated. In many cases, this isn’t a big deal. But if you have child components, they’ll re-render even when data hasn’t changed because each render allocates a new function.
Bottom line: Avoid declaring arrow functions or binding in render for optimal performance. My team uses
... read the whole story at medium.freecodecamp.org.