Skip to content

Commit

Permalink
Initial implementation of useSWRList
Browse files Browse the repository at this point in the history
Implemented in accordance with the [RFC][1]. Initial implementation is
mostly a copy/paste of `useSWR`, then moved things into arrays so we
can handle the list aspect of this correctly. Plenty of work still to be done,
especially around the duplication between `useSWRList` & `useSWR`,
plus more tests need to be written, but this gives us a basis for discussion.

  [1]: #1988
  • Loading branch information
mAAdhaTTah committed Jun 23, 2022
1 parent 790e044 commit 8ca9b80
Show file tree
Hide file tree
Showing 11 changed files with 798 additions and 15 deletions.
2 changes: 2 additions & 0 deletions _internal/index.ts
Expand Up @@ -23,3 +23,5 @@ export { withMiddleware } from './utils/with-middleware'
export { preload } from './utils/preload'

export * from './types'

export const WITH_DEDUPE = { dedupe: true }
12 changes: 12 additions & 0 deletions _internal/types.ts
Expand Up @@ -278,3 +278,15 @@ export interface StateDependencies {
isValidating?: boolean
isLoading?: boolean
}

export type DefinitelyTruthy<T> = false extends T
? never
: 0 extends T
? never
: '' extends T
? never
: null extends T
? never
: undefined extends T
? never
: T
18 changes: 3 additions & 15 deletions core/use-swr.ts
Expand Up @@ -31,23 +31,11 @@ import {
SWRConfiguration,
SWRHook,
RevalidateEvent,
StateDependencies
StateDependencies,
DefinitelyTruthy,
WITH_DEDUPE
} from 'swr/_internal'

const WITH_DEDUPE = { dedupe: true }

type DefinitelyTruthy<T> = false extends T
? never
: 0 extends T
? never
: '' extends T
? never
: null extends T
? never
: undefined extends T
? never
: T

export const useSWRHandler = <Data = any, Error = any>(
_key: Key,
fetcher: Fetcher<Data> | null,
Expand Down

0 comments on commit 8ca9b80

Please sign in to comment.