Skip to content

Custom cache provider #1017

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

Merged
merged 19 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/use-swr-infinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function useSWRInfinite<Data = any, Error = any>(
const resolvePageSize = useCallback((): number => {
const cachedPageSize = cache.get(pageSizeCacheKey)
return typeof cachedPageSize !== 'undefined' ? cachedPageSize : initialSize
}, [pageSizeCacheKey, initialSize])
}, [pageSizeCacheKey, initialSize, cache])
// keep the last page size to restore it with the persistSize option
const lastPageSizeRef = useRef<number>(resolvePageSize())

Expand Down Expand Up @@ -204,7 +204,7 @@ function useSWRInfinite<Data = any, Error = any>(
},
// immutability of rerender is guaranteed by React, but react-hooks/exhaustive-deps doesn't recognize it
// from `rerender = useState({})[1], so we put rerender here
[pageSizeCacheKey, resolvePageSize, mutate, rerender]
[pageSizeCacheKey, resolvePageSize, mutate, rerender, cache]
)

// Use getter functions to avoid unnecessary re-renders caused by triggering all the getters of the returned swr object
Expand Down
8 changes: 2 additions & 6 deletions src/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ const broadcastState: Broadcaster = (
) => {
const [, , CACHE_REVALIDATORS] = getGlobalState(cache)
const updaters = CACHE_REVALIDATORS[key]

const promises = []
if (updaters) {
const currentData = cache.get(key)
const currentError = cache.get(keyErr)
const currentIsValidating = cache.get(keyValidating)
const promises = []
for (let i = 0; i < updaters.length; ++i) {
promises.push(
updaters[i](shouldRevalidate, data, error, isValidating, i > 0)
Expand Down Expand Up @@ -645,7 +641,7 @@ function useSWR<Data = any, Error = any>(
(newData, shouldRevalidate) => {
return internalMutate(cache, keyRef.current, newData, shouldRevalidate)
},
[]
[cache]
)

// Define the SWR state.
Expand Down