T
TanStack•4y ago
like-gold

react-query triggers a re-reneder every X seconds on react native.

My query looks something like this
useQuery(['someKey'], somePromise, {
notifyOnChangeProps: ['data', 'isLoading'],
})
useQuery(['someKey'], somePromise, {
notifyOnChangeProps: ['data', 'isLoading'],
})
A simple query, but it is triggering a re-render every x seconds. Even when looking at the full object react query returns, no property is different. Is there something I am missing?
4 Replies
mute-gold
mute-gold•4y ago
what is somePromise. I hope it's a function that returns a promise?
like-gold
like-goldOP•4y ago
@TkDodo 🔮 yes, my promise is an axios get
export async function somePromise() {
try {
const response = await axios.get(`/foo`)

return response.data
} catch (error: unknown) {
return { error: error as AxiosError }
}
}
export async function somePromise() {
try {
const response = await axios.get(`/foo`)

return response.data
} catch (error: unknown) {
return { error: error as AxiosError }
}
}
mute-gold
mute-gold•4y ago
that should work except that the error handling is weird because you return a resolved promise, which will make react query not go into error state. are you sure you're not calling somePromise() directly during render? would need to see a codesandbox reproduction otherwise
like-gold
like-goldOP•4y ago
yeah, I am not using the promise directly, but I will double check. I will try to set up a codesanbox/expo snack to reproduce it. Thanks for the response c:

Did you find this page helpful?