Skip to content
Discussion options

You must be logged in to vote

if you want to have a component to retrieve query data, but not subscribe to it, you can do:

const data = queryClient.getQueryData(key)

if the component renders for whatever reason, it will get the latest data, otherwise, it won't re-render on it's own. I don't think it would solve your problem though. I would do:

const useFeed = (select) => useQuery(['feed'], () => fetchFeed(), { select })
const useSinglePost = (id) => useFeed(data => data.find(post => post.id === id))

then, in the feed view:

const { data } = useFeed()

data?.map(post => <SinglePost id={post.id} />

and in SinglePost:

const SinglePost = React.memo(({ id }) => {
  const { data } = useSinglePost(id)
  
  // render data h…

Replies: 2 comments 1 reply

Comment options

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

Comment options

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