Skip to content
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

Initial implementation of useSWRList #2047

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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