-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feature: allow using skipSymbol as arg in hooks #1056
Conversation
instead of the `skip` option
/** | ||
* Can be passed into `useQuery`, `useQueryState` or `useQuerySubscription` | ||
* instead of the query argument to get the same effect as if setting | ||
* `skip: true` in the query options. | ||
* | ||
* Useful for scenarios where a query should be skipped when `arg` is `undefined` | ||
* and TypeScript complains about it because `arg` is not allowed to be passed | ||
* in as `undefined`, such as | ||
* | ||
* ```ts | ||
* // codeblock-meta title="will error if the query argument is not allowed to be undefined" no-transpile | ||
* useSomeQuery(arg, { skip: !!arg }) | ||
* ``` | ||
* | ||
* ```ts | ||
* // codeblock-meta title="using skipSymbol instead" no-transpile | ||
* useSomeQuery(arg ?? skipSymbol) | ||
* ``` | ||
* | ||
* If passed directly into a query or mutation selector, that selector will always | ||
* return an uninitialized state. | ||
*/ | ||
export const skipSymbol = Symbol('skip selector') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should describe what it does ;)
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 ecaf556:
|
Size Change: +220 B (0%) Total Size: 535 kB
ℹ️ View Unchanged
|
Deploy preview for redux-starter-kit-docs ready! Built with commit ecaf556 https://deploy-preview-1056--redux-starter-kit-docs.netlify.app |
This still needs tests.
This will resolve
arg: ... | undefined
if{skip: true}
in useQuery rtk-incubator/rtk-query#220Thanks @omerman for the suggestion.
Naming is as always up for debate. @omerman suggested
skipToken
which should also fit the bill fine.@markerikson opinions?