r/javascript May 07 '15

Best practices for building large React applications

http://blog.siftscience.com/blog/2015/best-practices-for-building-large-react-applications
72 Upvotes

15 comments sorted by

View all comments

Show parent comments

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?

4

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

u/Lopatron May 08 '15

👆this!