Skip to content

Instantly share code, notes, and snippets.

@mjackson
Last active April 11, 2018 08:44
Show Gist options
  • Save mjackson/30099a91636c99a13a7ea9ca41bbb7a6 to your computer and use it in GitHub Desktop.
Save mjackson/30099a91636c99a13a7ea9ca41bbb7a6 to your computer and use it in GitHub Desktop.
More information about <Broadcast>/<Subscriber> deprecations in react-broadcast

<Broadcast> and <Subscriber> are being deprecated

<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

How to upgrade to the new API

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.

@philcockfield
Copy link

philcockfield commented Apr 11, 2018

What is the kind of value that should be put into createContext as the defaultValue @mjackson?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment