Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a placeholder data option #57

Open
minht11 opened this issue Jun 29, 2024 · 1 comment
Open

Add a placeholder data option #57

minht11 opened this issue Jun 29, 2024 · 1 comment
Assignees
Labels
✨ feature request a new feature request

Comments

@minht11
Copy link

minht11 commented Jun 29, 2024

Loading spinners are bad, it less disruptive to show users previous data until new data is ready. Suspense is somewhat based on that idea.

Have code like this:

const { data } = useQuery({
	key: () => ['item', props.selectedItemId],
	query: () => getItemById(props.selectedItemId),
})

when props.selectedItemId changes current behavior of useQuery forces me to show blank screen because data does not exist, I wish data would not be reset while isFetching is true.

@posva
Copy link
Owner

posva commented Jun 29, 2024

It’s normal it’s not kept by default. But maybe a placeholder option could add this

Notes:

  • It should allow a function placeholderData: (previousData) => Data
  • Must be sync
  • Must be compatible in type with the regular data
  • Should set the status to success
  • Need a way to transfer this piece of info during SSR to avoid using a placeholder data as initial data
  • should not be used in the cache as data, only be a fallback

@posva posva changed the title useQuery should keep previous data while new is fetching Add a placeholder data option Jun 30, 2024
@posva posva added the ✨ feature request a new feature request label Jun 30, 2024
@ElisePatrikainen ElisePatrikainen self-assigned this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request a new feature request
Projects
Status: In progress
Development

No branches or pull requests

3 participants