[英]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:数组中的每个元素都具有以下属性:
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.