useSWR giving error even after following official docs
Answered
Argentine hake posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Argentine hakeOP
I have used the following code, which can be found in official docs easily but it throws error
Answered by risky
your page probably isn't a [client component](https://nextjs-faq.com/when-client-component-in-app-router)
12 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Argentine hakeOP
import React from "react";
import useSWR from "swr";
const fetcher = (...args) => fetch(...args).then(res => res.json())
export default function App() {
const { data, error, isLoading } = useSWR(
"https://rickandmortyapi.com/api/character",
fetcher
);
if (error) return "An error has occurred.";
if (isLoading) return "Loading...";
return (
<>
Loading...
</>
);
}
it throws following error
![Image](https://cdn.discordapp.com/attachments/1176028404810784858/1176028638160896080/image.png?ex=656d6104&is=655aec04&hm=79d1b1f25535a3776cfa18fb216e21c58c6a738c15770cb8d575b4c8b699d2c2&)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
your page probably isn't a [client component](https://nextjs-faq.com/when-client-component-in-app-router)
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Argentine hakeOP
you are right, its working now
thanks dude
I have another question, not related to above issue though
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/c78dd8e985ede1ad50c31ac682dd91a1.webp?size=256)
risky
btw you shouldn't make your page a client component tho, instead keep it server and import client into it
can you open a new thread 🙂
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Argentine hakeOP
yes sir
sure
on it