React · Middle · Question 48 of 75
With pagination, how do you show the old page while the new one loads, instead of a skeleton?
- ✓Correct answer:
placeholderData: keepPreviousData - 2
staleTime: Infinityfor all pages - 3
refetchOnMount: falseon the query
Explanation
With a new key (['projects', page]), the query starts with an empty cache. placeholderData substitutes the previous data while the new data loads, and isPlaceholderData lets you, for example, disable the "Next" button. In v4 this was the keepPreviousData: true option.