Synchronous data selection #2441
Unanswered
tusgavomelo
asked this question in
Q&A
Replies: 1 comment
-
Even with useSelector from redux, the data that you select can possibly be undefined if you load it from the server first. So |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! Just to give you guys some context, I started learning about
react-query
a week ago and I come from aredux
background. Let me create an example scenario:I have an endpoint
/user-profile
that returns the following JSON:Following
react-query
docs I would end up with a very simple hook that should look something like this:Then I just need to call
useUserProfile
hook on any component I need usar data. This is my app structure:I need to call
useUserProfile
in all my 3 components and it will return{ data, isLoading, error, etc...}
, so I need to always assume thatdata
might not there during the first render. That causes a lot of duplicate logic likeif (isLoading)
orif (data)
on every component that uses this hook.Is there any different way to access the same information in different components in a sync way? I'm just wondering if there's something similar to
useSelector
fromreact-redux
.Beta Was this translation helpful? Give feedback.
All reactions