code: function ContextSubscriber(name) {
    const contextName = `@@contextSubscriber/${name}`
    const lastRenderedEventIndexKey = `${contextName}/lastRenderedEventIndex`
    const handleContextUpdateKey = `${contextName}/handleContextUpdate`
    const unsubscribeKey = `${contextName}/unsubscribe`
  
    return {
      contextTypes: {
        [contextName]: shape({
          subscribe: func.isRequired,
          eventIndex: number.isRequired
        })
      },
  
      getInitialState() {
        if (!this.context[contextName]) {
          return {}
        }
  
        return {
          [lastRenderedEventIndexKey]: this.context[contextName].eventIndex
        }
      },
  
      componentDidMount() {
        if (!this.context[contextName]) {
          return
        }
  
        this[unsubscribeKey] = this.context[contextName].subscribe(
          this[handleContextUpdateKey]
        )
      },
  
      componentWillReceiveProps() {
        if (!this.context[contextName]) {
          return
        }
  
        this.setState({
          [lastRenderedEventIndexKey]: this.context[contextName].eventIndex
        })
      },
  
      componentWillUnmount() {
        if (!this[unsubscribeKey]) {
          return
        }
  
        this[unsubscribeKey]()
        this[unsubscribeKey] = null
      },
  
      [handleContextUpdateKey](eventIndex) {
        if (eventIndex !== this.state[lastRenderedEventIndexKey]) {
          this.setState({[lastRenderedEventIndexKey]: eventIndex})
        }
      }
    }
  }
docs: Works around issues with context updates failing to propagate. Caveat: the context value is expected to never change its identity. https://github.com/facebook/react/issues/2517 https://github.com/reactjs/react-router/issues/470