Reputation: 11269
When developing using React, often there are components that are related to both a parent component and its children components. I always have a hard time to decide where I should put this type of components.
For example, a List component (parent) contains many SingleListItem components (children). When a user clicks a SingleListItem component, a Dialog component will popup. Should I place the Dialog component as the child of List or SingleListItem?
Please correct me if I am wrong:
Upvotes: 3
Views: 601
Reputation: 14101
My first inclination is to decide who is the parent of the dialog (list or listitem) based on
a. positioning of the dialog:
And on
b. effects of the dialog:
There is no difference between list or listitems choice in relation to your other points:
As to the amount of code there is also no difference:
The only difference is: if you put the dialog in listitem, your code to evaluate whether or not to display the dialog will be executed 1000 times. But it is practically impossible to make such an evaluation inefficient enough to notice any difference at all. Even with a 1000 lines. And as pointed out, there will be many other reasons not to render a 1000 lines if they do not fit on screen.
Hope this helps.
Upvotes: 6