Comments (2)
Good question, I'm gonna blog about this soon, so here is the TL;DR. We used to use setState
indeed for local component state but discovered that it gives more issues than using @observable
.
Too name a few:
- setState is asynchronous. If you call
setState
and after that call some other functions, they are still looking at the old state. I have seen leading this to very subtle things in the past - setState makes it appear that all component state is captured in the
state
field. But in practice this doesn't uphold always, as anysetState
call triggers a re-render, while sometimes there is local state that doesn't influence rendering,
Using @observable
fixes both this issues and has the nice upside that the component code becomes a lot more concises this.a = b
instead of this.setState({ a: b })
. And since local component state is now uniform with how you would use stores in MobX, it becomes way easier to factor local component state out when needed.
from mobx-contacts-list.
It makes sense and I would add (as a 3rd point) that doing so also ease debugging (with mobx 2.2 and the new @action
decorator).
Thank you for your quick answer and your great lib.
from mobx-contacts-list.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx-contacts-list.