Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(react-query): add pause provider #8756

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oblador
Copy link

@oblador oblador commented Mar 5, 2025

This implements a pause provider according to proposal in #8574 which functions similar to subscribed prop, but to a whole tree and without redundant re-renders.

Not decided on the correct behaviour if subscribed option is true, currently it will ignore this, but probably it should not.

See provided example for usage, happy to flesh out docs and tests if you think this is a viable approach.

I tried to use the examples/react/react-native project, but couldn't get it to start (probably because pnpm isn't compatible with RN).

This can easily be augmented with a more user friendly provider component along these lines:

export type PauseProviderProps = {
  paused: boolean
  children?: React.ReactNode
}

export const PauseProvider = ({
  paused,
  children,
}: PauseProviderProps): React.JSX.Element => {
  const pauseManager = React.useRef<PauseManager>(null)
  if (pauseManager.current === null) {
    pauseManager.current = new PauseManager(paused)
  }
  React.useEffect(() => {
    pauseManager.current?.setPaused(paused)
  }, [paused])
  return (
    <PauseManagerContext.Provider value={pauseManager}>
      {children}
    </PauseManagerContext.Provider>
  )
}

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation package: query-core package: react-query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant