Shown below is a snippet of the declaration of a function in my react component:
increment() {
this.setState(state => ({
count: state.count + 1
}));
}
Notice that there is parenthesis right after the arrow. I do not understand why this code wouldn't work without the parenthesis, since it wasn't required in another similar case:
toggleVisibility() {
this.setState(state => {
if (state.visibility === true) {
return { visibility: false };
} else {
return { visibility: true };
}
});
}
When do I use the parenthesis?
I'm a new self-learn coder, please be kind on me! Many thanks.