Skip to content

Handling more granular variants of fetch states with AsyncData or similar #40

Closed Answered by bloodyowl
momentiris asked this question in Q&A
Discussion options

You must be logged in to vote

hi!

for that case I'd recommend to use two AsyncData instances:

type ReloadableAsyncData<T> = {
  data: AsyncData<T>;
  nextData: AsyncData<T>;
}

In data you can keep the last committed update, and in nextData the current update:

// initial state
{data: AsyncData.NotAsked(), nextData: AsyncData.NotAsked()}
// first load
{data: AsyncData.Loading(), nextData: AsyncData.NotAsked()}
// first data received
{data: AsyncData.Done(v1), nextData: AsyncData.NotAsked()}
// reload started
{data: AsyncData.Done(v1), nextData: AsyncData.Loading()}
// reload done
{data: AsyncData.Done(v2), nextData: AsyncData.NotAsked()}

this modeling also works for paginated queries, where you can aggregate in data and…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@momentiris
Comment options

Answer selected by bloodyowl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #39 on September 29, 2022 08:38.