Comments (5)
I'm outside the React/Flux team but this is my understanding of things, it might be wrong.
-
Stores are the source of truth, they are event emitters and are listened to by the components. The
setState
call is because React has no observables so it must be told when the component needs to be rendered, that data would almost always come from Stores so in reality it's not state that the React components would mutate, they simply rendered it to the screen. -
Yes the fact Stores etc are all Singletons is a problem for us in our particular use of Flux. We have solved it by using a factory to return instances of Stores etc. We might write a blog post about it soon.
from flux.
- React does have a setProps method which re-renders the component. However it can only be called by top level components. They specifically discourage you from using it (or so it seems) but they do suggest in the docs that only one source of truth should exist in the app - aka components should not duplicate it. I just feel like I'm missing something here :)
- I'd be very interested in reading that - do drop a line if / when you do
from flux.
-
Props are immutable and passed in from your parent, state is mutable and local to the component. This aids in pinpointing bugs. I think if you relied on your parent feeding all data from Stores into you as props you would be asking React to do too much unnecessary work. Anyway the only ways that parents could trigger a render of them self is either via
setState
or a force update. The Stores are the source of truth, you can't ask your React components for that data, you can only ask the Stores. -
Will do.
from flux.
Thanks, Brian for clarifying this for Guy and other readers! I believe you
have it correct.
I'd like to add that the Sections in this example are at the second level
of the hierarchy, quite near the top. They receive no props -- as
controller-views they are the source of props for all their children.
Please also note that there is no "hard rule" about the level of the
hierarchy where controller-views should live. I find that debugging is
easier when you keep them at the top, but there are benefits to having low
level ones too -- this allows you to encapsulate code better (not pass down
a lot of extra data in the props). Like I said, I much prefer keeping them
at the top and passing data down, but other people here at Facebook feel
otherwise. Different strokes.
I'm very curious as to why stores as singletons were problematic for you,
so I'm looking forward to reading a blog post about that too.
On Sat, Aug 23, 2014 at 12:41 PM, Brian Di Palma [email protected]
wrote:
Props are immutable and passed in from your parent, state is mutable
and local to the component. This aids in pinpointing bugs. I think if you
relied on your parent feeding all data from Stores into you as props you
would be asking React to do too much unnecessary work. Anyway the only ways
that parents could trigger a render of them self is either via setState
or a force update. The Stores are the source of truth, you can't ask your
React components for that data, you can only ask the Stores.Will do.
—
Reply to this email directly or view it on GitHub
#41 (comment).
Bill Fisher
510.414.8771
http://fisherwebdev.com
from flux.
Thanks @fisherwebdev @briandipalma was somewhat confused about this.
fyi - http://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html can be interpreted as saying you should use setProps when getting data from stores.
Closing this for now
from flux.
Related Issues (20)
- Cannot dispatch in the middle of a dispatch. HOT 1
- New Flux store instance created upon second component referencing store HOT 7
- Flux Utils + Hooks HOT 6
- TypeError: Class constructor App cannot be invoked without 'new' HOT 1
- Using version of fbjs that depends on unsupported core-js module HOT 2
- Please update the following components: FluxContainer(containerClass) React 16.10.2 HOT 5
- how do we differ from Architecture and pattern? HOT 1
- Is this code a good way to update react component from dispatch in OOP class object? HOT 2
- Flux container breaks class methods defined with class properties syntax HOT 1
- Container create context issues after Babel 7.9.x update. HOT 5
- CVE-2020-15168 found in [email protected] HOT 13
- CVE-2020-7733 vulnerability by linking to an older fbjs version HOT 2
- Is fbemitter project discontinued? Is flux? HOT 1
- Add React 17 support
- NPM reports flux vulnerabilities HOT 3
- CVE-2021-27292: ua-parser-js needs to upgrade to 0.7.24 HOT 4
- mock flux store - react test HOT 2
- Will there be a Chinese version? HOT 1
- Video goes off screen and does not fit neatly HOT 1
- Add react-18 as peer dependency. HOT 1
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 flux.