can i export data isLoading error from reactQuery?

Please i need some help here. 🙏 I fetched data[] from an API using reactQuery but the problem I'm facing here is that i need to export all the properties decontructed from reactQuery such as the data[], isLoading, error so that i can be able to use it in another component, is this possible? I name the file userData.tsx
export const UserData = () => {
const { data, isLoading, error } = useQuery<User[], ErrorConstructor>("query-users", async () =>{
return await getAll()
})
if(error instanceof Error) return <div>Cannot fetch data</div>

if(isLoading) return <LoadingState/>

if(!data) return <div>Error occour</div>
return (
data
)
}
export const UserData = () => {
const { data, isLoading, error } = useQuery<User[], ErrorConstructor>("query-users", async () =>{
return await getAll()
})
if(error instanceof Error) return <div>Cannot fetch data</div>

if(isLoading) return <LoadingState/>

if(!data) return <div>Error occour</div>
return (
data
)
}
5 Replies
thatsbro
thatsbro3y ago
You can use prop or redux Rtk to send data.
Coder_Carl
Coder_Carl3y ago
either set it up through context OR put it into the common ancestor and pass it through as props
Daryl
Daryl3y ago
React Query as a State Manager
Everything you need to know to make React Query your single source of truth state manager for your async state
Daryl
Daryl3y ago
The QueryKey uniquely identifies your query, so as long you call the query with the same key in two different places, they will get the same data.
The QueryKey uniquely identifies your query, so as long you call the query with the same key in two different places, they will get the same data.
Leke
LekeOP3y ago
Ok Let me take a look at the article
Want results from more Discord servers?
Add your server