Skip to content

Error when use Promise .then(): Cannot modify '...', the object is protected and can only be modified by using an action. #2005

Closed Answered by coolsoftwaretyler
KyryloSWAN asked this question in Q&A
Discussion options

You must be logged in to vote

So I think when you chain off a promise with .then(), you turn the .then() clause into effectively an async function call.

That pulls the code execution outside of the async generator you're using, and MST doesn't allow changing state outside actions

You said your last code block is bad, but I think that's the correct thing to do here. Assuming apiFetchDestinations is some async function that returns a response (which would have been value in your .then() method), it should work.

Can you say more about what's bad about your last block which yields the response value and uses it afterward? Or perhaps send a CodeSandbox to illustrate additional problems you're having?

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@KyryloSWAN
Comment options

@coolsoftwaretyler
Comment options

@coolsoftwaretyler
Comment options

Answer selected by KyryloSWAN
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants