Answer the question
In order to leave comments, you need to log in
Props or State if there is only one update?
In the application, the tree structure of the components, the final, deepest, I will call “leaves”. Leaves have id's that are stored in the application. And also from an external service for these id receive additional. data: eg. avatar and link.
Initially, the application receives the data on which this tree is built, and only the id for the end nodes, these leaves . And then you have to ask for more. data from an external service in order to correctly draw these leaves . That. it has two states: freshly created , with only -id, and having received all the data from an external service a little later. User add. The data does not change in any way, they are only needed for display.
When the user adds new branches, and then "hangs" new leaves on them , everything is the same: first only the id, then the request and additional. data in the redrawing of the leaf .
Question: following the philosophy of ReactJS, should the id be passed along the props chain, and the request should be additional. data to initiate in each of the leaves individually, and received additional. store data in state; or pass everything from the root of the entire application through props throughout the cascade of nested components; or something else?
Answer the question
In order to leave comments, you need to log in
A good solution is to make some components at the top of the tree as Controller-View , which will have a state and receive data, but otherwise try to keep the components stateless ( doc ).
React.js is so flexible that it gives us a free hand: everyone is able to come up with their own original solution. With the advent of Flux and its repositories, I began to use the principle of passing a minimum set of data through props; everything that the component can take itself, let it take itself . Thus, my component most often receives only an id, and when rendering, it will independently receive the missing data from external sources.
In your case, if there are no external sources, store the data directly in the state of the component.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question