feat: Improve Controller.getResponse() interface #1396
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BREAKING CHANGE: useDenormalized() return type changed
{
data: DenormalizeNullable<Shape['schema']>;
expiryStatus: ExpiryStatus;
expiresAt: number;
}
Motivation
Manifest expiry policy within getResponse() to make it more obvious what to do
Solution
Since the interface must changed for useDenormalized() and we want to get rid of it; mark as deprecated and make useStatefulResource() no longer depend on it.
Expiry behavior goal is https://resthooks.io/docs/getting-started/expiry-policy#expiry-status
However, triggering mechanisms are dependent on hook implementation, therefore we want to cede control of triggering the fetch and describe the behavior based on how that plays.
To describe we introduce
Valid
InvalidIfStale
Invalid
Alternatives
I did consider returning two methods:
To correctly trigger fetches this would maintain referential equality until expiresAt or forceFetch change
This would change
To
Follow up
In a subsequent PR, will add useSuspense: