T
TanStack•14mo ago
correct-apricot

useQuery don't not call under async method

here the useQuery call
const { status } = useQuery({
queryKey: ['events'],
queryFn: fetchEventUseCase.executeList
})
const { status } = useQuery({
queryKey: ['events'],
queryFn: fetchEventUseCase.executeList
})
the executeList method
async executeList(): Promise<Event[]> {
console.log('fetching events from usecase');
const events = await this.eventRepository.listUserEvents()
this.updateStoreList(events)
return events
}
async executeList(): Promise<Event[]> {
console.log('fetching events from usecase');
const events = await this.eventRepository.listUserEvents()
this.updateStoreList(events)
return events
}
And listUserEvents
async listUserEvents(): Promise<Event[]> {
console.log('fetching events from api');
const response = await fetch(`/api/events`);
const data = await response.json();
const parsedData = z.array(eventSchema).parse(data);
return parsedData.map(mapEventToDomain);
}
async listUserEvents(): Promise<Event[]> {
console.log('fetching events from api');
const response = await fetch(`/api/events`);
const data = await response.json();
const parsedData = z.array(eventSchema).parse(data);
return parsedData.map(mapEventToDomain);
}
The executeList is triggered but the listUserEvents is not triggered, when I try with useEffect everything work but with useQuery the console.log('fetching events from api'); is not print and I don't understand why I'm really new with this lib I probably miss something Thank for your help 🙂
1 Reply
correct-apricot
correct-apricotOP•14mo ago
everything work fine It was just the this context which was lost I just use anonymous func and it's good now 🙂

Did you find this page helpful?