Since I originally answered this question, it’s become apparent to me that React itself doesn’t support “global” data in any sense – it is truly meant to manage the UI and that’s it. The data of your app needs to live somewhere else. Having said that, it does now support accessing global context
data as detailed in this other answer on this page. Here’s a good article by Kent Dodds on how the context
api has evolved, and is now officially supported in React.
The context
approach should only be used for truly global data. If your data falls into any other category, then you should do as follows:
- Facebook themselves solve this problem using their own Flux library.
- Mobx and Redux are similar to Flux, but seem to have more popular appeal. They do the same thing, but in a cleaner, more intuitive way.
I’m leaving my original edits to this answer below, for some history.
OLD ANSWER:
The best answer I’ve found for this so far are these 2 React mixins, which I haven’t had a chance to try, but they sound like they’ll address this problem:
https://github.com/dustingetz/react-cursor
and this similar library:
https://github.com/mquan/cortex
MAJOR NOTE: I think this is a job for Facebook’s Flux, or something similar (which the above are). When the data flow gets too complex, another mechanism is required to communicate between components other than callbacks, and Flux and it’s clones seem to be it….