Skip to content

Commit

Permalink
Backport compat fix for React 18 strict effects
Browse files Browse the repository at this point in the history
Subscriptions in Provider need to be set up in the effect, not in
the `useMemo` hook.

Port of commit 9a210fd from 8.x development
  • Loading branch information
markerikson committed Apr 1, 2022
1 parent b325eb9 commit 54ff7a6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
function Provider({ store, context, children }) {
const contextValue = useMemo(() => {
const subscription = createSubscription(store)
subscription.onStateChange = subscription.notifyNestedSubs
return {
store,
subscription,
Expand All @@ -18,6 +17,7 @@ function Provider({ store, context, children }) {

useIsomorphicLayoutEffect(() => {
const { subscription } = contextValue
subscription.onStateChange = subscription.notifyNestedSubs
subscription.trySubscribe()

if (previousState !== store.getState()) {
Expand Down

0 comments on commit 54ff7a6

Please sign in to comment.