I am facing issue with react query when I try to destructing the data like this way const {data: getAllChannelSettingTypes} = useGetAllChannelSettingTypes(); I am gettin this error Property 'data' does not exist on type 'void'
Maybe there is a problem with returning the 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:
The useQueries hook returns an array with all the query results.
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]
try removing the params "data"