0 votes
in ReactJS by
Is it good to use arrow functions in render methods in Reactjs, explain with example?

1 Answer

0 votes
by

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

...