<Broadcast>
and <Subscriber>
are being deprecated in react-broadcast in favor of a new API inspired by the new React context RFC. The goals of this change for react-broadcast users are:
- Make it easier to upgrade to the new React context API when it eventually lands
- Remove ambiguity around channels
Instead of using pre-built <Broadcast>
and <Subscriber>
components, you create them for yourself. So instead of:
// Don't do this anymore.
import { Broadcast, Subscriber } from 'react-broadcast'
you use createContext
instead:
// Do this instead!
import { createContext } from 'react-broadcast'
const { Broadcast, Subscriber } = createContext(defaultValue)
The defaultValue
is a new feature introduced in the RFC that allows <Subscriber>
s to be rendered outside the context of their <Broadcast>
and still get a value by default instead of nothing.
What is the kind of value that should be put into
createContext
as thedefaultValue
@mjackson?