Skip to content
doubtly

2 answers

Arrow functions do not have their own this; they take this from the surrounding code. In React class components this keeps this pointing to the component in event handlers without using bind().

class Counter extends React.Component {
  state = { count: 0 };

  // arrow function: 'this' is the component
  handleClick = () => {
    this.setState({ count: this.state.count + 1 });
  };

  render() {
    return <button onClick={this.handleClick}>{this.state.count}</button>;
  }
}

With a normal method, this would be undefined when the handler is called by the button click, giving an error, unless you write this.handleClick = this.handleClick.bind(this) in the constructor. Arrow functions avoid this bug. They are also used inline, e.g. onClick={() => this.delete(id)} to pass arguments, and inside map() to render lists.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.