Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.6 KB

conditional-fetching.mdx

File metadata and controls

41 lines (31 loc) · 1.6 KB
id title sidebar_label hide_title description
conditional-fetching
Conditional Fetching
Conditional Fetching
true
RTK Query > Usage > Conditional Fetching: skipping fetching if needed

 

Conditional Fetching

Overview

Query hooks automatically begin fetching data as soon as the component is mounted. But, there are use cases where you may want to delay fetching data until some condition becomes true. RTK Query supports conditional fetching to enable that behavior.

If you want to prevent a query from automatically running, you can use the skip parameter in a hook.

examples

remarks

:::tip Typescript users may wish to use skipToken as an alternative to the skip option in order to skip running a query, while still keeping types for the endpoint accurate. :::

Conditional Fetching Example

<iframe src="https://codesandbox.io/embed/github/reduxjs/redux-toolkit/tree/master/examples/query/react/conditional-fetching?fontsize=12&runonclick=1&hidenavigation=1&module=%2Fsrc%2FPokemon.tsx&moduleview=1&theme=dark" style={{ width: '100%', height: '600px', border: 0, borderRadius: '4px', overflow: 'hidden', }} title="Conditional Fetching Example" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" ></iframe>