[英]How performance will impact with react relay if we use loadQuery and usePreloadedQuery vs loadQuery and useLazyLoadQuery hook?
So practically both ways are same or different?那么实际上这两种方式是相同的还是不同的? In terms of good architecture what should be the preferred way and why?
就良好的架构而言,首选方式应该是什么?为什么?
usePreloadedQuery
sends the request while the component is rendering, and can suspend with a loading state if the component is ready before the query returns. usePreloadedQuery
在组件呈现时发送请求,如果组件在查询返回之前准备就绪,则可以挂起加载 state。
On the other hand useLazyLoadQuery
sends the request after the component has rendered.另一方面,
useLazyLoadQuery
在组件呈现后发送请求。
Because API requests generally take longer than React renders, it is better to start fetching as early as possible.因为 API 请求通常比 React 渲染花费的时间更长,所以最好尽早开始获取。 Using prefetching with
React.Suspense
also improves user experience, because they won't see the component rendering nothing or an empty initial state before becoming populated with data.将预取与
React.Suspense
一起使用还可以改善用户体验,因为在填充数据之前,他们不会看到组件呈现任何内容或空的初始 state。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.