Answer the question
In order to leave comments, you need to log in
How to optimize react-mobx rendering?
There is a simple mobx class:
class CntStore {
@observable counter;
@observable counter2;
constructor() {
this.counter = 0;
this.counter2 = 0;
}
setTest() {
console.log("SET counter");
this.counter = 1; // это вызовет функцию render у соответствующего react компонента
console.log("SET counter2");
this.counter2 = 1; // после этого снова вызовется функция render
console.log("return setTest");
}
}
Answer the question
In order to leave comments, you need to log in
Found a reason. In permalinks, it was necessary to set /%postname%/ and I had /%category%/%postname%/
use an action decorator for the method + wrap any async callbacks that will be inside the method e.g.
@action
setTest() {
this.counter = 1;
this.counter2 = 1;
//здесь будет только один рендер
setTimeout(action(()=>{
this.counter = 1;
this.counter2 = 1;
//здесь тоже будет только один рендер
}),1000)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question