2 answers
The arrow function helps you to predict the behavior of bugs when passed as a callback. Therefore, it prevents bug caused by this all together.
codelikepro
· 19 Aug 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
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?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.