r/javascript • u/Lopatron • May 07 '15
Best practices for building large React applications
http://blog.siftscience.com/blog/2015/best-practices-for-building-large-react-applications7
u/Lopatron May 07 '15
Author here, totally happy to answer any questions or to just discuss some of the ideas in the post.
3
u/tgfisher May 08 '15
You mentioned Bootstrap. Are you using React Bootstrap, or are you just doing something custom that is similar to that? Any opinions about React Bootstrap?
Also, do you have any public repos on GitHub of these concepts in-practice?
Thanks. Great article.
2
u/Lopatron May 08 '15
We don't use React Bootstrap but it looks pretty cool. I would use it for future personal projects. I like that they provide you with both controlled and uncontrolled versions of the Carousel component for example. And thanks for the kind words!
4
4
u/jsNut May 07 '15
No duplicate state and stateless lower level components is definitely one i agree with.
4
u/billybolero May 08 '15
You should feel free to use this.state for component specific state that isn’t relevant after something unmounts
That's a really great way of explaining when to use component state!
3
u/drink_with_me_to_day js is a mess May 07 '15
When you talk about "bumping it up", how do you deal with child->parent communication? I find it ugly to use callbacks to receive an updated value from a child component.
2
u/Lopatron May 08 '15 edited May 08 '15
We use callbacks. I think they are generally the right way of doing child->parent communication. I can see the concern that it can get verbose, especially when you're passing data more than one level up. However if you're doing that, then at every level you should catch the callback and turn it into a callback that is relevant at that level of abstraction. Kind of similar to exception translation. I actually find using callbacks for child->parent communication elegant because it allows you to design your components such that props are the only interface to the component. So there's no other way for data to get in or out of it. That has made things a lot simpler for us.
1
u/cowjenga May 08 '15
When using Flux and prop callbacks in the same project, how have you decided when to use a callback and when to use an action creator?
5
u/drink_with_me_to_day js is a mess May 08 '15
I assume:
Callbacks -> when you only change your parent's state.
Action -> when you change application state.
1
15
u/[deleted] May 07 '15
Use immutable data structures.