Skip to content

Commit 54ff7a6

Browse files
committed
Backport compat fix for React 18 strict effects
Subscriptions in Provider need to be set up in the effect, not in the `useMemo` hook. Port of commit 9a210fd from 8.x development
1 parent b325eb9 commit 54ff7a6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/components/Provider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
77
function Provider({ store, context, children }) {
88
const contextValue = useMemo(() => {
99
const subscription = createSubscription(store)
10-
subscription.onStateChange = subscription.notifyNestedSubs
1110
return {
1211
store,
1312
subscription,
@@ -18,6 +17,7 @@ function Provider({ store, context, children }) {
1817

1918
useIsomorphicLayoutEffect(() => {
2019
const { subscription } = contextValue
20+
subscription.onStateChange = subscription.notifyNestedSubs
2121
subscription.trySubscribe()
2222

2323
if (previousState !== store.getState()) {

0 commit comments

Comments
 (0)