Skip to content

Commit 77ba3aa

Browse files
committed
polish truthy key
1 parent 3565fdd commit 77ba3aa

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

_internal/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ export type KeyedMutator<Data> = (
228228
data?: Data | Promise<Data> | MutatorCallback<Data>,
229229
opts?: boolean | MutatorOptions<Data>
230230
) => Promise<Data | undefined>
231-
// Public types
232231

233232
export type SWRConfiguration<
234233
Data = any,

core/use-swr.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,7 @@ export const useSWRHandler = <Data = any, Error = any>(
440440
// By using `bind` we don't need to modify the size of the rest arguments.
441441
// Due to https://github.com/microsoft/TypeScript/issues/37181, we have to
442442
// cast it to any for now.
443-
async (...args) => {
444-
return internalMutate<Data>(cache, keyRef.current, ...args)
445-
},
443+
internalMutate.bind(UNDEFINED, cache, keyRef.current) as any,
446444
// eslint-disable-next-line react-hooks/exhaustive-deps
447445
[]
448446
)
@@ -459,9 +457,10 @@ export const useSWRHandler = <Data = any, Error = any>(
459457
})
460458

461459
useIsomorphicLayoutEffect(() => {
462-
if (_key && key) KEYS.add(_key)
460+
const isTruthyKey = _key && key && !isFunction(_key)
461+
if (isTruthyKey) KEYS.add(_key)
463462
return () => {
464-
if (_key && key) KEYS.delete(_key)
463+
if (isTruthyKey) KEYS.delete(_key)
465464
}
466465
}, [_key])
467466

0 commit comments

Comments
 (0)