Answer the question
In order to leave comments, you need to log in
Is it possible to write functions in React this way?
There is such a function in the code:
handleClick = () => {
this.setState(state => ({ isActive: !state.isActive }));
};
handleClick = function handleClick() {
this.setState(function (state) {
return {
isActive: !state.isActive
};
});
};
handleClick = function() {
this.setState(function (state) {
return {
isActive: !state.isActive
};
});
};
Answer the question
In order to leave comments, you need to log in
Is it possible to write functions like this according to React rules? That is, to have the word function and return?
You can use pure js in react
Nobody forbids you to write functions with the word function and return. But you should understand that when you write arrow functions you don't have a problem with context loss, but when you write functions like this
handleClick = function() {
this.setState(function (state) {
return {
isActive: !state.isActive
};
});
};
this.handleClick=this.handleClick.bind()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question