Delay isPending render
Typical code:
If my query is fast, this results in some flashing (imagine skeletons etc.)
I was wondering if some of you did some sort of delay (like 0.1s) before rendering the skeleton). How did you do it?
This could have these advantages: no flashing, no unnecessary render, better accessibility.
4 Replies
rare-sapphire•12mo ago
You can add an animation using some lib, or use a debounced
isPending
rare-sapphire•12mo ago
You can use https://usehooks.com/usedebounce for the debounce. Just use
const debouncedIsPending = useDebounce(isPending, 500)
. This way debouncedIsPending
can update at most once every 500 msuseDebounce React Hook – useHooks
Delay the execution of function or state update with useDebounce.
harsh-harlequin•12mo ago
or implement your own, this starts a timeout to set
false
everytime bool
becomes false
, but lets true
through and clears the timeoutlike-goldOP•12mo ago
Thank you!