TanStackT
TanStack13mo ago
6 replies
thick-teal

Why the data i get from the useQuery it's undefined on the first render?

So i have this file with my axios request:
import { api } from "../lib/axios";
import type { Todo } from "../types/users";

export async function getTodos() {
    const response = await api.get<Todo[]>('/todos')
    
    return response.data
}


And this is in other file where im using useQuery
const { data:todosData } = useQuery({
    queryKey: ['todos'],
    queryFn: () => getTodos(),         
})

console.log(todosData.value, 'todosData value')
/\ this come as undefined 


Why my todosData from usingQuery is undefined at first render and only take the data from resquest if i save the request file?

Is there a way to in first render the todoData render the data from request?
Was this page helpful?