This repository has been archived by the owner on Dec 31, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 351
Is autorun
equivalent to componentWillReact
?
#62
Comments
Personally I find it quite naturally to react to prop changes. But so far I didn't need to react to other observables (besides rendering of course) in a component. Usually I put that kind of logic in a store / controller. Nonetheless the autorun solution is fine. Don't forget to dispose it on componentWillUnmount! |
Oh thanks for reminding me to dispose of the autorun. I completely forgot about that. |
@mweststrate : A quick Question , how do i dispose an autorun/reaction in componentWillUnmount? componentWillMount() { How do I dispose this in componentWillUnmount? |
reaction will return a function, that, if you call it, will dispose the
reaction. So just store it somewhere on `this`, and call it on willUnmount
Op do 1 mrt. 2018 om 20:23 schreef Sanyam Agrawal <notifications@github.com
…:
@mweststrate <https://github.com/mweststrate> : A quick Question , how do
i dispose an autorun/reaction in componentWillUnmount?
componentWillMount() {
reaction(
() => this.props.aggregateStore.filters,
this.fetchData
);
}
How do I dispose this in componentWillUnmount?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#62 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhC_UWxcxIXCKpasb63wCFSrJ1nO1ks5taEqZgaJpZM4IupiQ>
.
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm excited about MobX. I was able to reduce the code size significantly by switching from Redux to MobX. Thanks for the great library!
One of the things I usually need in my components is to do some logic whenever a certain prop has changed. Previously, I used to do that logic in
componentDidMount
and incomponentWillReceiveProps
. But now I have another source of data: MobX store. Changes happening to mobx data don't triggercomponentWillReceiveProps
but insteadcomponentWillReact
. So now I need to do that logic incomponentWillReact
as well.To reduce the number of lifecycle methods I use, I thought of doing:
Is the above equivalent to:
?
My guess is that the autorun solution is even better because it re-triggers the logic based on changes in the data that the logic cares about. As opposed to the latter which re-triggers the logic based on changes in data that the render cares about. Am I correct?
The text was updated successfully, but these errors were encountered: