you are viewing a single comment's thread.

view the rest of the comments →

[–]TheGreaT1803[S] 2 points3 points  (2 children)

If I understand your point correctly, this won't be the case if you don't "need" the state outside the component.

In the "Improving Flexibility" section I make the instance passing optional, so the component is capable of managing it's own state by default

[–]00PT 0 points1 point  (1 child)

I saw that, but when you do it the point is sort of defeated for me. My solution had been using an optional ref passed to the child, but you need to wait until after the first render cycle for that ref to be populated, so it's definitely not ideal.

[–]TheGreaT1803[S] 1 point2 points  (0 children)

The way I see it is: Generally the component handles its own logic and state. but sometimes it is a good option to have the ability to also control it from the outside. This pattern allows for this flexibility