Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

state is treated like observable and calls componentWillReact every change #185

Closed
rlesniak opened this issue Dec 22, 2016 · 4 comments
Closed

Comments

@rlesniak
Copy link

rlesniak commented Dec 22, 2016

I found this issue while update from 3.5.9 to 4.0.3

Reproduced here: JSBin (play with mobx-react version in HTML tab)

On older version mobx-react was calling componentWillReact only once - when I change observable value. Now its calling every time I do setState in my handleChange event. 3.5.9 didnt have this behavior.
I treat this like a bug because I didn't mark my state as observable so mobx should not treat it like observable.

But if its a feature ( ͡° ͜ʖ ͡°) then plase help me with bringing back my target behavior without rollbacking version. Thanks.

@Strate
Copy link
Contributor

Strate commented Dec 26, 2016

This was made as a feature together with #124.
As for now, both props and state are observables. Do you really need that granular discrimination between state reaction and obervable reaction? Because your component actually has a re-render of state changed, and now you can use your state in computed properties.

If you need to do something only on blur, why just not to do it onBlur?

@rlesniak
Copy link
Author

rlesniak commented Dec 29, 2016

All right, I found workaround, I use reaction instead of my previous solution.

Maybe you should update README because now there is misleading info:

componentWillReact won't fire when receiving new props or after setState calls (use componentWillUpdate instead)

but it is not true anymore since 4.0.0. I am right?

@Strate
Copy link
Contributor

Strate commented Dec 29, 2016

@rlesniak I suggest you to use computed for parsed number and 2nd observable variable, which sets on blur and used in calculation of computed variable. Then you do not need to use reaction.

Strate added a commit that referenced this issue Dec 29, 2016
mobx-react@4 has changed semantic of `props` and `state`, which became observables. So, this not became obsolete too.

#185
@Strate
Copy link
Contributor

Strate commented Dec 29, 2016

@rlesniak I've changed the readme, so, gonna to close this issue. Feel free to reopen if you have any questions left.

@Strate Strate closed this as completed Dec 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants