Skip to content

Commit bb3e2df

Browse files
committed
Manually update the stale context value
1 parent d485096 commit bb3e2df

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/ContextUtils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ export function ContextProvider(name) {
4343
},
4444

4545
componentDidUpdate() {
46+
const nextValue = this.getChildContext()[name]
4647
this[listenersKey].forEach(listener =>
47-
listener(this[eventIndexKey])
48+
listener(this[eventIndexKey], nextValue)
4849
)
4950
},
5051

@@ -111,8 +112,12 @@ export function ContextSubscriber(name) {
111112
this[unsubscribeKey] = null
112113
},
113114

114-
[handleContextUpdateKey](eventIndex) {
115+
[handleContextUpdateKey](eventIndex, nextValue) {
115116
if (eventIndex !== this.state[lastRenderedEventIndexKey]) {
117+
if (this.context[name] !== nextValue) {
118+
// React uses a stale value so we update it manually.
119+
this.context[name] = nextValue
120+
}
116121
this.setState({ [lastRenderedEventIndexKey]: eventIndex })
117122
}
118123
}

0 commit comments

Comments
 (0)