redux-toolkit
redux-toolkit copied to clipboard
Add skip condition on endpoint definition
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
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 |
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
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 | undefinednow assume
skipcould 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.
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?
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 :(