Skip to content

mobx6: Dynamic action #2651

Answered by kubk
mogadanez asked this question in Q&A
Discussion options

You must be logged in to vote

You can either disable action enforcing by setting "enforeActions": "never" or wrap all observable assignments into action/runInAction:

            if (store[loadFlag]) return
            store[loadFlag] = true
            try {
                const result = await loaderFn(options);
                runInAction(() => {
                  store[targetProp].replace(result)
                })
                return true
            }
            catch (e) {
                store.setError( name, extractErrorMessage(e) )
            }
            finally {
              runInAction(() => {
                store[loadFlag] = false
              })
            }

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mogadanez
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
3 participants