Skip to content

Why reactions should be used sparingly? #3544

Answered by urugator
alexkuc asked this question in Q&A
Discussion options

You must be logged in to vote

I can ensur a consistent state of data.

You can't. All reactions wait until your system is already in a consistent state (that's when action is finished):

autorun(() => this.b = this.a + 1)

@action doSomething() {
  this.a + 1;
  console.log(this.b) // inconsistent, not updated yet
}

Also there is no guaranteed order:

autorun(() => this.b = this.a + 1)
autorun(() => this.c = this.b + 1)
// these can run in whathever order

Lastly it (arguably) leads to a bad architecture, don't want to go into lengthy details, just a simple example. Imagine you wanna find out what happens when you click on something:

@action onClick() {
  this.a = 5;
}

Ok, so a changes to 5, simple ... except if you use…

Replies: 1 comment 1 reply

Comment options

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

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