大家好,提前致谢。
首先,我知道天气数据不适合 RTK 查询,因为它总是在变化,在这种情况下我使用 RTK 查询只是出于练习目的。我想在单击按钮时重新获取天气数据,但组件没有更新,但是requestId通过检查控制台,我可以看到单击刷新按钮时确实发生了变化,并且正在检索数据。我正在按照官方文档中的示例进行重新获取:
我还想知道使用 useLazyQuery 及其trigger函数是否更合适......
https://redux-toolkit.js.org/rtk-query/api/created-api/hooks#uselazyquery
...但如果是这样,我应该考虑什么才能决定使用 useQuery 还是 useLazyQuery?
import {
IonButton,
IonButtons,
IonCard,
IonCol,
IonContent,
IonGrid,
IonHeader,
IonPage,
IonRow,
IonTitle,
IonToolbar,
} from "@ionic/react";
import styles from "./Tab1.module.css";
import { RefreshOutline } from "react-ionicons";
import { Geolocation } from "@capacitor/geolocation";
import { useEffect } from "react";
import { RootState } from "../app/store";
import { useDispatch, useSelector } from "react-redux";
import { useGetCurrentPositionWeatherQuery } from "../services/weather";
import { setQueryCoord } …Run Code Online (Sandbox Code Playgroud)