Skip to content

What is the best (or alternate) ways to fetch the server data from a child component when the parent component hits an api that returns all the data that we need? #1619

Answered by TkDodo
dannynhois asked this question in Q&A
Discussion options

You must be logged in to vote

what I don't like about queryClient.getQueryData is two things:

  • it doesn't create a subscription - it only retrieves the data from the cache if it is rendered (for whatever reason), but it doesn't render per se when the underlying data changes. Now this might not be a problem in this case, but if you re-use your component or change the structure where <Child1A> is not rendered under <Parent> anymore - it will not work.
  • basically, similar to the first point: It's unexpected that the component will not "work" anymore if it's rendered as a child of another component. components are not meant to work only if put in a specific order (leaving our <Providers> here on purpose :)) - they are mean…

Replies: 4 comments 16 replies

Comment options

You must be logged in to vote
1 reply
@tannerlinsley
Comment options

Answer selected by dannynhois
Comment options

You must be logged in to vote
14 replies
@bertho-zero
Comment options

@TkDodo
Comment options

@bertho-zero
Comment options

@TkDodo
Comment options

@bertho-zero
Comment options

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants