英文:
Is there a way to extract data from prefetch in order to pass as a parameter to another prefetch in React-query
问题
标题已经包含了基本信息。
我获取了一些数据,然后我需要一些额外的数据,但我需要一个ID值,这个ID值只能从第一次获取的数据中获取。整个页面都是SSG,我想知道是否有一种方法可以使用react-query来实现这个逻辑。
英文:
The title says it all, basically.
I fetch some data and then I want some additional data, but I need an ID value which I can only get from the first fetch's data. The whole page is SSG and I was wondering if there is a way to implement this logic with prefetch using react-query.
答案1
得分: 0
queryClient.prefetchQuery
故意不返回任何数据,但是你可以使用queryClient.fetchQuery
,它会返回数据。但请记住,你需要处理错误,因为fetchQuery
不会这样做,而prefetch
会。实际上,这是prefetchQuery
的整个实现(为了简洁起见,省略了TS泛型):
prefetchQuery(options) {
return this.fetchQuery(options).then(noop).catch(noop)
}
英文:
queryClient.prefetchQuery
doesn't return any data on purpose, however, you can use queryClient.fetchQuery
instead, which does return data. But keep in mind that you need to handle errors, because fetchQuery
doesn't do that, while prefetch
does. In fact, this is the whole implementation of prefetchQuery
(leaving out the TS generics for brevity):
prefetchQuery(options) {
return this.fetchQuery(options).then(noop).catch(noop)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论