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
adding resetPages to clear cached pages on new searches #243
Conversation
Published to |
Published |
I am faced with issues with pagination this pull request is trying to solve, but I do not like that this pull request changes the function type signature to remove types altogether. This is a breaking change that blocks type inference for the arguments passed to the useSWRPages hook. Could we try to restore types before merging this pull request? |
@patrickus looks like you have configured eslint or prettier to add semicolons to your code and is changing the code style this repo has. It won't be merged with those changes in the code style. |
I need this feature to be merged. If @patrickus doesn't want to keep working on it, I can take over this branch and finish the work if the SWR team thinks that this is the right approach :) |
Hi, I had the same problem as @gabrielperales so I worked on a fix on my account. |
import { | ||
pagesResponseInterface, | ||
responseInterface, | ||
pageComponentType, | ||
pageOffsetMapperType | ||
} from './types' | ||
|
||
import { cacheGet, cacheSet } from './config' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
import { cacheGet, cacheSet } from './config' | |
import { cache } from './config' |
Then use cache.get and cache.set instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, hadn't pulled the latest changes, will integrate
const isEmpty = isReachingEnd && pageCount === 1 && emptyPageRef.current | ||
const loadMore = useCallback(() => { | ||
if (isLoadingMore || isReachingEnd) return | ||
if (isLoadingMore || isReachingEnd) | ||
return | ||
setPageCount(c => { | ||
cacheSet(pageCountKey, c + 1) | ||
return c + 1 | ||
}) | ||
}, [isLoadingMore || isReachingEnd]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to add pageCountKey
as @innocentiv has done here https://github.com/zeit/swr/pull/269/files#diff-c9d2eb3ea821da85bd697b22fe31edf4R153.
|
||
// Reset page if the key changes | ||
useEffect(() => resetPages(), [pageOffsetKey]) | ||
// Doesn't have a next page | ||
const isReachingEnd = pageOffsets[pageCount] === null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be pageOffsets[Math.max(1, pageOffsets.length - 1)] === null
?
I think we can close this due to the new useSWRInfinite API: #435. It should have solved this problem (and other related ones). As always, thank you for your awesome contribution! 🙏 |
Adding a Reset for pages
reference:
https://github.com/gabrielperales/swr/commit/8ba8379d2e6c580ded234385d34ea829be996788
resolving: #189
thanks https://github.com/gabrielperales