Skip to content

Commit

Permalink
Merge pull request #2277 from reduxjs/pr/fix-apiprovider-listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Jul 2, 2022
2 parents 82c0660 + a5551ee commit ee86c42
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/toolkit/src/query/react/ApiProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { configureStore } from '@reduxjs/toolkit'
import type { Context } from 'react'
import { Context, useEffect } from 'react'
import React from 'react'
import type { ReactReduxContextValue } from 'react-redux'
import { Provider } from 'react-redux'
Expand Down Expand Up @@ -33,7 +33,7 @@ import type { Api } from '@reduxjs/toolkit/dist/query/apiTypes'
export function ApiProvider<A extends Api<any, {}, any, any>>(props: {
children: any
api: A
setupListeners?: Parameters<typeof setupListeners>[1]
setupListeners?: Parameters<typeof setupListeners>[1] | false
context?: Context<ReactReduxContextValue>
}) {
const [store] = React.useState(() =>
Expand All @@ -45,7 +45,13 @@ export function ApiProvider<A extends Api<any, {}, any, any>>(props: {
})
)
// Adds the event listeners for online/offline/focus/etc
setupListeners(store.dispatch, props.setupListeners)
useEffect(
(): undefined | (() => void) =>
props.setupListeners === false
? undefined
: setupListeners(store.dispatch, props.setupListeners),
[props.setupListeners]
)

return (
<Provider store={store} context={props.context}>
Expand Down

0 comments on commit ee86c42

Please sign in to comment.