Skip to content

How use reaction with flow? #1919

Answered by EmilTholin
Yrsafam asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Yrsafam!

You could probably put fetchData in a separate actions block to have it always have a parent context:

// ...
.actions((self) => ({
  fetchData: flow(function* () {
    // ...
    let result = yield getData();
    // ...
  }),
}))
.actions((self) => ({
  afterCreate() {
    const disposerReaction = reaction(
      () => self.field,
      self.fetchData
    );

    addDisposer(self, disposerReaction);
  },
}));

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Yrsafam
Comment options

Answer selected by Yrsafam
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