MCPcopy Create free account
hub / github.com/ReactTraining/react-broadcast / createContextSubscriber

Function createContextSubscriber

modules/index.js:51–87  ·  view source on GitHub ↗
(contextKey)

Source from the content-addressed store, hash-verified

49)
50
51const createContextSubscriber = (contextKey) => (
52
53 class Subscriber extends React.Component {
54
55 static propTypes = {
56 children: PropTypes.func
57 }
58
59 static contextTypes = {
60 [contextKey]: PropTypes.object
61 }
62
63 constructor(props, context) {
64 super()
65 const emitter = context[contextKey]
66 if (emitter) {
67 this.state = {
68 value: emitter.getInitialValue()
69 }
70 this.unsubscribe = emitter.subscribe((value) => {
71 this.setState({ value })
72 })
73 } else {
74 this.state = {}
75 }
76 }
77
78 componentWillUnmount() {
79 this.unsubscribe()
80 }
81
82 render() {
83 return this.props.children(this.state.value)
84 }
85
86 }
87)
88
89export { createContextEmitter, createContextSubscriber }

Callers 2

coords.jsFile · 0.90
index-test.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…