为什么我对personDataSend的第二次调用设置isLoading值在TEK查询Mutations 查询中不起作用?当您第一次执行onClick时,isLoading为真,但在第二次单击时,它不是真,在第二次单击时,值仍然为假.

const [
  getDriverLicenseByPin,
  { data, isLoading },
] = useLazyGetDriverLicenseByPinQuery();
  
const personDataSend = (values) => {
  getDriverLicenseByPin({
    pin: values.Pin,
    driverLicenseNumber: values.DriverLicenseNumber,
  });
};

推荐答案

收件箱实际上只加载一次,例如尚未缓存数据时.您可能希望使用isFetching状态,每当查询主动获取时,该状态都为真.

useLazyQuery:

type UseQueryStateResult<T> = {
  // Base query state
  originalArgs?: unknown // Arguments passed to the query
  data?: T // The latest returned result regardless of trigger arg, if present
  currentData?: T // The latest returned result for the trigger arg, if present
  error?: unknown // Error result if present
  requestId?: string // A string generated by RTK Query
  endpointName?: string // The name of the given endpoint for the query
  startedTimeStamp?: number // Timestamp for when the query was initiated
  fulfilledTimeStamp?: number // Timestamp for when the query was completed

  isUninitialized: false // Query has not started yet.
  isLoading: false // Query is currently loading for the first time. No data yet.
  isFetching: false // Query is currently fetching, but might have data from an earlier request.
  isSuccess: false // Query has data from a successful load.
  isError: false // Query is currently in an "error" state.
}

更新您的逻辑以也引用isFetching状态,当重新触发/重新获取查询端点时,该状态应该为真.

const [
  getDriverLicenseByPin,
  { data, isLoading: isLoadingData, isFetching },
] = useLazyGetDriverLicenseByPinQuery();

const isLoading = isLoadingData || isFetching;
  
const personDataSend = (values) => {
  getDriverLicenseByPin({
    pin: values.Pin,
    driverLicenseNumber: values.DriverLicenseNumber,
  });
};

Javascript相关问答推荐

我可以获取所有包含@的超链接,然后在新选项卡中打开它们吗?

原型链中的同一财产怎么会有不同的价值?

使用Element.children在前后移动 node

如何指定1条记录1个表?

JS、C++和C#给出不同的Base 64 Guid编码结果

成帧器运动中的运动组件为何以收件箱开始?

如何访问Json返回的ASP.NET Core 6中的导航图像属性

在页面上滚动 timeshift 动垂直滚动条

如何在RTK上设置轮询,每24小时

docx.js:如何在客户端使用文档修补程序

仅针对RTK查询中的未经授权的错误取消maxRetries

在Vite React库中添加子模块路径

闭包是将值复制到内存的另一个位置吗?

如何将innerHTML字符串修剪为其中的特定元素?

使用auth.js保护API路由的Next.JS,FETCH()不起作用

用于部分字符串的JavaScript数组搜索

如果NetSuite中为空,则限制筛选

如何使用[ModelJSON,ArrayBuffer]调用tf.loadGraphModelSync

如何在每隔2分钟刷新OKTA令牌后停止页面刷新

未捕获的不变违规:即使在使用DndProvider之后也应使用拖放上下文