-
The TS compiler is complaining about a possible undefined variable when using the key callback pattern: const { session } = useSession()
useSWR(() => ["/v2/order/recipe/summary", session.id], This will complain that |
Beta Was this translation helpful? Give feedback.
Answered by
sergiodxa
Sep 21, 2020
Replies: 1 comment 1 reply
-
You can use a condition const { session } = useSession()
useSWR(() => session?.id ? ["/v2/order/recipe/summary", session.id] : null, fetcher); This way, SWR will not run the fetch until session is defined which will prevent possible failing requests. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
pke
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a condition
This way, SWR will not run the fetch until session is defined which will prevent possible failing requests.