useSWR data returns undefined but I can see the data in the fetcher function #683
Answered
by
promer94
ksoenandar
asked this question in
Q&A
Replies: 2 comments 5 replies
-
const fetcher = (url) => {
return fetch(url) **// You miss the return statement here**
.then((r) => r.json())
.then((data) => {
console.log(data); <- returns data as expected
return { user: data?.user || null };
});
}; |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ksoenandar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using useSWR in my NextJS project but I'm having trouble with it returning undefined.
hooks.jsx
When I console logged the 'data' in the fetcher function, it returns the data as expected. However, in the main useUser function, the 'data' returns undefined. What am I doing wrong?
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions