useSWR giving error even after following official docs
Answered
Argentine hake posted this in #help-forum
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
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
your page probably isn't a [client component](https://nextjs-faq.com/when-client-component-in-app-router)
Answer
Argentine hakeOP
you are right, its working now
thanks dude
I have another question, not related to above issue though
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 🙂
Argentine hakeOP
yes sir
sure
on it