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.

class Foo extends Component {
handleClick() {
console.log('Click happened');
}
render() {
return <button onClick={() => this.handleClick()}>Click Me</button>;
}
}

Note: Using an arrow function in render method creates a new function each time the component renders, which may have performance implications


Author of content
Edit this page

Made by Michael Sakhniuk

Twitter