redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Add skip condition on endpoint definition

Open SYoder1 opened this issue 10 months ago • 4 comments

Adds a skip condition function to the endpoint definition to "skip" making the network request when returned true. Instead of needing to set the skip on every query hook it can be applied at a more global layer.

In order to keep isUninitialized set to true, the same way it works with skip on the hook, I needed to add a check for it in the useQuery hook.

Closes #4810

SYoder1 avatar Jan 13 '25 19:01 SYoder1

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

codesandbox[bot] avatar Jan 13 '25 19:01 codesandbox[bot]

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 00aaf8733d87b0839489de69a8f363a1703f2b86:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

codesandbox-ci[bot] avatar Jan 13 '25 19:01 codesandbox-ci[bot]

Deploy Preview for redux-starter-kit-docs ready!

Name Link
Latest commit 00aaf8733d87b0839489de69a8f363a1703f2b86
Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/680b9d089e762a0008d93cdc
Deploy Preview https://deploy-preview-4813--redux-starter-kit-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Jan 13 '25 19:01 netlify[bot]

From some internal discussion:

If we ever had suspense hooks, that could be a serious blockers for correct types for those, just to bring that up

  const data = useSuspenseQuery({ ... })
  // ^? MyDataType
  const data = useSuspenseQuery(skipToken)
  // ^? undefined
  const data = useSuspenseQuery(foo ? skipToken : { ... })
  // ^? MyDataType | undefined

now assume skip could be set somewhere else, the first case would have to be | undefined

which is a valid concern.

I like the idea of this option, but it also feels like it will need some deeper consideration to figure out ramifications.

markerikson avatar May 06 '25 19:05 markerikson

Hey @markerikson, just circling back to this, is there anything I can do on my end for this or does this need to be solved at a project level since it effects other things already?

SYoder1 avatar Oct 09 '25 14:10 SYoder1

Unfortunately it's not something I'm going to have time to look at any time soon. My current focus is wrapping up the Immer perf work, and then I'll be turning my attention to React-Redux.

I think the last comment is still where things stand - I like the idea conceptually, it's reasonable, but I'm pretty sure this will end up having some unexpected impacts and we'd need time to try to figure out what those might be.

I realize that's a very unsatisfying answer, and I apologize that I don't have more concrete feedback at this point :(

markerikson avatar Oct 17 '25 01:10 markerikson