0

My question is similar to this one: How to manage component rendering when there are several small, repeatable sub-components

I am building a RequirementsList component, which has a list of 'Requirement' components.

  • Each Requirement may have 0 or more Comment components.
  • When the requirements data is fetched from server, associated comments are not fetched immediately (lazy loading).
  • So, first rendering will show only basic part of the requirement. When user clicks on the comments tab, the comments component in comments tab makes a call to the store to fetch the comments.
  • Now when comments are successfully fetched from server, I want to re-render the affected comments tab.

I am in a dilemma on how to propagate the received comments data to the comments component. I can see a couple of options:

  • Comments Component listens for store event, gets the data and updates itself. This is straight and simple. But violates the principle of data flow from parent.
  • Parent root component (RequirementsList) listens to store, and propagates the results as props. In this case, I donno how? The parent is only listening for list of requirements, and not for comments against each requirements.

So, I presume that first option is the right way to go, as the parent doesn't care in managing the data for some Comment component deep down the hierarchy.

Are there any better suggestions for this?

Community
  • 1
  • 1
Mopparthy Ravindranath
  • 3,014
  • 6
  • 41
  • 78
  • 1
    Hi Mupparthy, in my opinion there is nothing wrong to call actions from the child components, it is even cleaner and make sense with the "events triggers - event listeneres" concept. try to read this blog post where there is an example of sub-components call actions and how it communicates with it's parent components http://www.dimagimburg.com/reflux-sweeper-react-reflux-and-immutablejs-explained-by-example/ – Dima Gimburg Dec 12 '15 at 11:49

1 Answers1

0

I would probably go with option two. You stated that the comments are related to the selected requirement. I would also be inclined to load the comments when the requirement is selected rather than the comment tab. This should provide a better user experience.

J. Mark Stevens
  • 4,911
  • 2
  • 13
  • 18