Sto utilizzando MobX 2.2.2 per provare a modificare lo stato all'interno di un'azione asincrona. Devo usare useStrict di MobX su true.Utilizzo del decoratore MobX @action con funzioni asincrone e .then
@action someAsyncFunction(args) {
fetch(`http://localhost:8080/some_url`, {
method: 'POST',
body: {
args
}
})
.then(res => res.json())
.then(json => this.someStateProperty = json)
.catch(error => {
throw new Error(error)
});
}
ottengo:
Error: Error: [mobx] Invariant failed: It is not allowed to create or change state outside an `action` when MobX is in strict mode. Wrap the current method in `action` if this state change is intended
ho bisogno di fornire il decoratore @Action alla seconda affermazione .then? Qualsiasi aiuto sarebbe apprezzato.
come fare questo in async/aspettano? – TangMonk