Skip to content

Commit

Permalink
polish truthy key
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed May 26, 2022
1 parent 3565fdd commit 77ba3aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion _internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ export type KeyedMutator<Data> = (
data?: Data | Promise<Data> | MutatorCallback<Data>,
opts?: boolean | MutatorOptions<Data>
) => Promise<Data | undefined>
// Public types

export type SWRConfiguration<
Data = any,
Expand Down
9 changes: 4 additions & 5 deletions core/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ export const useSWRHandler = <Data = any, Error = any>(
// By using `bind` we don't need to modify the size of the rest arguments.
// Due to https://github.com/microsoft/TypeScript/issues/37181, we have to
// cast it to any for now.
async (...args) => {
return internalMutate<Data>(cache, keyRef.current, ...args)
},
internalMutate.bind(UNDEFINED, cache, keyRef.current) as any,
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
)
Expand All @@ -459,9 +457,10 @@ export const useSWRHandler = <Data = any, Error = any>(
})

useIsomorphicLayoutEffect(() => {
if (_key && key) KEYS.add(_key)
const isTruthyKey = _key && key && !isFunction(_key)
if (isTruthyKey) KEYS.add(_key)
return () => {
if (_key && key) KEYS.delete(_key)
if (isTruthyKey) KEYS.delete(_key)
}
}, [_key])

Expand Down

0 comments on commit 77ba3aa

Please sign in to comment.