Skip to content

Why autorun runs before unmounting a component? #3058

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

You must be logged in to vote

autorun/reaction is completely unaware of the component and it's lifecycle. It simply runs at the end of outermost action (transaction) - the order is not exactly specified - meaning one reaction/autorun shouldn't depend on another. Here, you assume that App (observer) is invalidated and rendered before autorun, which is not the case.
Also the effect's disposer function has a low priority I think (?), so it will always run after any autorun (not sure). (Probably not, it would be a bit inconvinient)
It also means that autorun may not see correct props as mentioned here: mobxjs/mobx-react#772 (comment) (3rd paragraph)

Replies: 1 comment 1 reply

Comment options

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

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