-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
typeof 'data' is always optional even with 'fallbackData' provided. #1410
Comments
Any plans to resolve this issue? It's so confusing especially while I am using Shared Hook State with SWR which is updated feature at for example use case, export function useEmail() {
const { data: email, mutate: setEmail } = useSWR('@email-key', {
fallbackData: '',
fetcher: undefined,
});
return [email!, setEmail] as const;
} |
Is there any update on this issue? |
It is weird that data can still be undefined even though fallbackData is set. |
Still an issue in v2.1.5. Anyway coercion is always a workaround, but it is still strange because #2301 seems to have fixed this with |
dont specify generic, it need fetcher and fallbackData to infer the type |
Thanks for the info! It works: // string | undefined
const { data } = useSWR<string>("/api", { suspense: true })
// string
const { data } = useSWR("/api", fetcher<string>, { suspense: true }) |
Bug report
Description / Observed Behavior
type of
data
Expected Behavior
type of
data
should beData
(notData | undefined
) iffallbackData
has provided in typeData
.Repro Steps / Code Example
SWR version.
1.0.0
The text was updated successfully, but these errors were encountered: