Reliably communicate state changes to deeply nested React elements
Reliably communicate state changes to deeply nested React elements
react-broadcast provides a reliable way for React components to propagate state changes to their descendants deep in the component hierarchy, bypassing intermediaries who return false from shouldComponentUpdate.
It was originally built to solve issues that arose from using react-router together with react-redux. The router needed a safe way to communicate state changes to ``s deep in the component hierarchy, but react-redux relies on shouldComponentUpdate for performance. react-broadcast allows the router to work seamlessly with Redux and any other component that uses shouldComponentUpdate.
Please note: As with anything that uses context, this library is experimental. It may cease working in some future version of React. For now, it's a practical workaround for the router. If we discover some better way to do things in the future, rest assured we'll do our best to share what we learn.
$ npm install --save react-broadcast
Then, use as you would anything else:
// using ES6 modules
import { createContext } from "react-broadcast";
// using CommonJS modules
var createContext = require("react-broadcast").createContext;
The UMD build is also available on unpkg:
You can find the library on window.ReactBroadcast.
The following is a contrived example, but illustrates the basic functionality we're after:
…
Enjoy!
react-broadcast is developed and maintained by React Training. If you're interested in learning more about what React can do for your company, please get in touch!
No open issues yet, or sync has not completed.