TanStackT
TanStack3y ago
7 replies
ordinary-sapphire

life cycle timing problem with useQuery

My application needs to load general config data via an ajax request. This config contains things like BASE_URL, STALE_TIME and other constants.

When I initialize my useQuery, I need these constants to set up the request. Here's a code snippet to help understanding the problem:

const store = useStore(); onBeforeMount(async ()=>{ const response = await fetch('./config.json'); const json = await response.json(); store.config.value = json; }); const { data } = useRecordQuery(store.config.value);

When I initialize the useRecordQuery, the store.config will be
undefined
. How do you solve this timing issue. I can't put the useRecordQuery in the lifecycle hook.
Was this page helpful?