首页 > 其他 > 详细

[React] Get Previous Resource Values with React’s useDeferredState Hook

时间:2020-04-24 10:40:18      阅读:74      评论:0      收藏:0      [点我收藏+]

The useDeferredValue Hook gives us a way to hold onto a previous resource values while waiting for a new one.

This is a more hands-on alternative to the magic of useTransition.
With useTransition, React "keeps" the previous rendering and gives you a magical isPending boolean to conditionally show loading UI.

useDeferredValue puts you in the driver seat by giving you the actual value.
This value can be used to implement our own isPending.

 

let [startTransition] = React.useTransition();
let defferedPokemonResource = React.useDeferredValue(pokemonResource, {
 timeoutMs: 3000
});
let pokemon = deferredPokemonResource.read();
let isPending = deferredPokemonResource !== pokemonResource;

 

Not commonly used, only when you need to know what is the previous value and what is the current one

[React] Get Previous Resource Values with React’s useDeferredState Hook

原文:https://www.cnblogs.com/Answer1215/p/12764985.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!