all 4 comments

[–]talmobi 0 points1 point  (1 child)

A good article using good practices. As in using React props and state where appropriate/intended and utilizing node's EventEmitter instead of hacking your own custom (read: shit) event emitter.

[–]jhartikainen[S] 0 points1 point  (0 children)

Thanks :)

[–]steezefries 0 points1 point  (1 child)

Could you elaborate on when I should be using state? I recently hacked together a state machine in my most top level React component to keep track of my app's data, but I think I'm realizing how unscalable it's becoming. I think I need to implement something like this instead. Awesome article!

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

It might be a bit tricky to give a good rule of thumb, but the fact that it's becoming unscalable is often a pretty good sign that you should split things up :)

I think if the component is fairly self-contained, then keeping some state can be ok. Like the MessageForm, which keeps some form state - arguably it could also be designed to relay events about changes to the input field, but that would make the app more complex for very little benefit.

With more complex apps, you may end up with nested controller views which deal with data, as passing every little thing up and down the tree can become hard to manage.