简体   繁体   English

当我尝试从反应查询中破坏数据时,我得到属性“数据”在“无效”类型上不存在

[英]when I try to destructing the data from react query I am getting Property 'data' does not exist on type 'void'

I am facing issue with react query when I try to destructing the data like this way const {data: getAllChannelSettingTypes} = useGetAllChannelSettingTypes();当我尝试像这样破坏数据时,我遇到了反应查询的问题const {data: getAllChannelSettingTypes} = useGetAllChannelSettingTypes(); I am gettin this error Property 'data' does not exist on type 'void'我收到此错误Property 'data' does not exist on type 'void'

Maybe there is a problem with returning the userQueries返回 userQueries 可能有问题

const useGetAllChannelSettingTypes = () => {
  const {data: defaultSettingTypes} = useQuery(SETTING_TYPES, () =>
    Api.user.getSettingTypes(),
  );
  const userQueries = useQueries(
    defaultSettingTypes.map((type: any) => {
      return {
        queryKey: ['SETTING_VALUE', type.channelSettingTypeId],
        queryFn: () => Api.user.getSettingValues(type.channelSettingTypeId),
      };
    }),
  );
  console.log(userQueries);
  return userQueries;
};

According to the documentation useQueries returns an array:根据文档useQueries 返回一个数组:

The useQueries hook returns an array with all the query results. useQueries 挂钩返回一个包含所有查询结果的数组。

Each element in the array has these properties:数组中的每个元素都具有以下属性:

  • status: String状态:字符串
  • isIdle: boolean isIdle:布尔值
  • isLoading: boolean isLoading:布尔值
  • isSuccess: boolean isSuccess:布尔值
  • isError: boolean isError:布尔值
  • isLoadingError: boolean isLoadingError: 布尔值
  • isRefetchError: boolean isRefetchError: 布尔值
  • data : TData, defaults to undefined . dataTData,默认为 undefined
  • dataUpdatedAt: number dataUpdatedAt:数字
  • error: null |错误:空| TError恐怖
  • errorUpdatedAt: number错误更新时间:数字
  • isStale: boolean isStale:布尔值
  • isPlaceholderData: boolean isPlaceholderData:布尔值
  • isPreviousData: boolean isPreviousData:布尔值
  • isFetched: boolean isFetched:布尔值
  • isFetchedAfterMount: boolean isFetchedAfterMount:布尔值
  • isFetching: boolean isFetching:布尔值
  • isRefetching: boolean isRefetching:布尔值
  • failureCount: number失败计数:数字
  • errorUpdateCount: number错误更新计数:数字
  • refetch: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise refetch: (options: { throwOnError: boolean, cancelRefetch: boolean }) => Promise
  • remove: () => void删除:() => 无效

So try destructing the data in a loop like this:所以尝试像这样在循环中破坏数据:

 for(let i = 0; i < userQueries.length; i++){ const {data: getAllChannelSettingTypes} = useGetAllChannelSettingTypes() // do something with that data of the given query }

If you are only interested in the first result you could do it like this:如果您只对第一个结果感兴趣,您可以这样做:

 const {data: getAllChannelSettingTypes} = useGetAllChannelSettingTypes()[0]

尝试删除参数“数据”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用天气api,我正在尝试从中获取数据但未定义但属性确实存在 - I am trying to use a weather api that I am trying to pull data from i am getting undefined but the property does exist “RelayObservable”类型上不存在属性“then”<unknown> '。 当我尝试在反应中使用中继获取数据时。 我不知道为什么会出现这个错误</unknown> - Property 'then' does not exist on type 'RelayObservable<unknown>'. when I try to fetch data using relay in react. I don't know why this error come 类型上不存在属性`data`<void> | AxiosHttpResponse<any> - Property `data` does not exist on Type <void> | AxiosHttpResponse<any> Redux 操作中的“void”类型不存在属性“数据” - Property 'data' does not exist on type 'void' in Redux action 从服务订阅数据时,类型 void 上不存在错误属性订阅? - error property subscribe doesn't exist on type void when subscribe data from service? 类型 void 上不存在属性 - Property does not exist on type void 当我尝试在 vue3 打字稿中执行内联三元运算符时,出现“布尔类型上不存在属性类型”错误 - i Get a "Property type does not exist on type boolean" error when i try to do an inline ternary operator in vue3 typescript 虽然我返回了Promise,但属性在void类型上不存在 - Property then doesn't exist on type void, although I am returning a Promise 在 GraphQL 查询之后:属性 'then' 在类型 'void' 上不存在 - After GraphQL Query: Property 'then' does not exist on type 'void' 尝试从标签获取数据时获取未定义的值 - Getting an undefined value when I try to get data from a label
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM