Ich benutze MobX 2.2.2, um zu versuchen, den Status innerhalb einer asynchronen Aktion zu ändern. Ich habe MobX useStrict auf wahr gesetzt.Verwenden des MobX @action Dekorators mit asynchronen Funktionen und dann
@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)
});
}
ich:
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
Muss ich den @action Dekorateur auf die zweite .then Erklärung liefern? Jede Hilfe wäre willkommen.
, wie dies zu tun in async/await? – TangMonk