Here is an example:
onChange = (event, { newValue }) => {
this.setState({
value: newValue
});
};
Is this any different from
onChange(e, {newValue}) {
this.setState({
value: newValue
});
}
Thanks!
Here is an example:
onChange = (event, { newValue }) => {
this.setState({
value: newValue
});
};
Is this any different from
onChange(e, {newValue}) {
this.setState({
value: newValue
});
}
Thanks!
Yes, there is:
onChange = (event, { newValue }) => {
this.setState({
value: newValue
});
};
will retrieve this
from the outer scope of the function, so it would refer to the this
of the place where it was defined at.
onChange(e, {newValue}) {
this.setState({
value: newValue
});
}
On this, this
will refer to the this
that the function is called with, so this
would not refer to the this
from where it was called from but from the object it is binded to.
For more information check Arrow Functions (MDN)
The arrow function version binds to the this
context - probably what you want for an event callback.