Vite, React, useQuery, API, Streaming

Hey, guys! I am new here and i a junior. I was curious if anyone can give me an advice on one question (React, useQuery, Streaming). Lets say you have some amount of data that you need to pull from backend, when you load the page (like posts, news, list of user profiles, etc... does not really matter). The point is its more than 1 type of data. Currently i have custom hook for page itself and for data types (in order not to bloat the page itself). But, i also need to do the checks with isLoading for every data type, because Suspense does not work if i just pass the (for some time) undefined data into component. So how you deal with this situation? I dont want to have x*data isLoading checks and it is a little pain to destructure all that.
Solution:
Are you planning to add the different hook calls (useNews, useUsers) into useHomepage? If so, I don't see the benefit of a "page hook". I would move each call to the specific component. I.e. PostList will call usePosts and deal with the loading state. You can also write a skeleton wrapper for the components that need a loading state. ...
Jump to solution
2 Replies
Solution
LP
LP•12mo ago
Are you planning to add the different hook calls (useNews, useUsers) into useHomepage? If so, I don't see the benefit of a "page hook". I would move each call to the specific component. I.e. PostList will call usePosts and deal with the loading state. You can also write a skeleton wrapper for the components that need a loading state. I never tried React Query but I used SWR and it does not play well with Suspense.
Nikita Shtimenko
Nikita ShtimenkoOP•12mo ago
"Are you planning to add the different hook calls (useNews, useUsers) into useHomepage?" Yes, thats the point. Already solved it (your way), but thank you for the answer 🙂
Want results from more Discord servers?
Add your server