Hey everyone,
Got a JS syntax question regarding arrow functions. Ill post the code first so the question will be easier to understand:
render() {
return (
<button className="square"
onClick={() => this.setState({value: 'X'})}>
{this.state.value}
</button>
);
}
}
This is a code fragment from a React app. The onClick handler calls an arrow function to this.setState.
Why isn’t this.setState in curly brackets like a normal function? What are some other use cases for this syntax?
Thank you in advance!