React & Modern Frontend (445 Qs)•Part 11: Legacy Architecture, Migration Patterns & Historical Internals (354 - 445)
Is it good to use arrow functions in render methods?
Yes, You can use. It is often the easiest way to pass parameters to callback functions. But you need to optimize the performance while using it.
javascript
class Foo extends Component {
handleClick() {
console.log("Click happened");
}
render() {
return <button onClick={() => this.handleClick()}>Click Me</button>;
}
}
sql
**Note:** Using an arrow function in render method creates a new function each time the component renders, which may have performance implications