docs: add comprehensive documentation for useSWRInfinite revalidation behavior and infinite loading example#4255
Closed
ruguoba wants to merge 2 commits into
Closed
docs: add comprehensive documentation for useSWRInfinite revalidation behavior and infinite loading example#4255ruguoba wants to merge 2 commits into
ruguoba wants to merge 2 commits into
Conversation
… behavior This documentation explains: - Why only the first page is revalidated by default - How to use revalidateFirstPage option - How to use revalidateAll option - Best practices for different use cases - Common questions and answers Closes #785
…allback This example demonstrates how to implement infinite loading using: - useSWRInfinite for data fetching - IntersectionObserver for scroll detection - useCallback to prevent infinite loops - useRef for observer management Addresses #883
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR adds comprehensive documentation for
useSWRInfinite's revalidation behavior and a practical infinite loading example, addressing the confusion raised in #785 and #883.Changes
1. Revalidation Behavior Documentation (
docs/infinite-revalidation.md)revalidateFirstPagerevalidateAllrevalidateIfStale2. Infinite Loading Example (
examples/infinite-loading-intersection-observer.md)useSWRInfinitewithIntersectionObserveruseCallbackto prevent infinite loopsWhy This Documentation Is Needed
Issue #785 - Revalidation Behavior Confusion
Many users have been confused by the default behavior of
useSWRInfinitewhere only the first page is revalidated when loading new pages. This documentation clarifies:Issue #883 - Infinite Loop with IntersectionObserver
Users reported infinite loops when using
setSizewithIntersectionObserver. The new example demonstrates:useCallbackto prevent function recreationuseRefto store the observerRelated Issues
Testing
This is a documentation-only change, so no code testing is required. The documentation has been reviewed for accuracy based on the existing codebase and the discussion in #785 and #883.
Note: This documentation aims to help users understand the design decisions behind
useSWRInfinite's revalidation behavior and provide clear guidance on how to implement infinite loading with IntersectionObserver without encountering infinite loops.