TanStackT
TanStack3y ago
4 replies
wet-aqua

Data isn't being passed into function correctly

Super weird bug, I use a QueryFN to execute an API call. This is something I've done a million times before (in fact immediately below the code I am about to share, I run another few API calls that use extremely similar syntax.

I pass in two variables into the function, one called "appUrl" and another called "isApp" -- when I console.log them, they look how I want them to look... isApp is a bool that gets set correctly, appUrl is indicitive of what I want it to be too... then I call useQuery...

const info = useQuery(['info'], ()=>getInfo(appUrl, isApp), {onSuccess:(data)=> setResID(data.data[0].id)})

Here are the clientside logs for both isApp and appUrl. I log them immediately ABOVE useQuery.

[Log] true

[Log] order.[redacted].com


It calls the following function

export const getInfo = (appUrl, isApp) => api.post(process.env.NEXT_PUBLIC_PROTOCOL+`://${window.location.host}/api/restaurants/`, {url: isApp ? appUrl : window.location.host}).then(res=> {
    res.data
    console.log(isApp)
    console.log(appUrl)
})


isApp is undefined. It's not undefined when I pass it in. appUrl logs this out:

[Log] {queryKey: ["info"], pageParam: undefined, meta: undefined}

What the heck is happening here? This makes absolutely zero sense.

My app is made up of 30+ API calls... I use this syntax time after time with no issues... please help! Thanks in advance!
Was this page helpful?