So I am trying to fetch an API using NextJS and I am using SWR.
My code is as follows:
import useSWR from "swr";
const fetcher = (url: string) => fetch(url).then((res) => res.json());
export default function Home(){
const { data, error, isLoading } = useSWR(
"https://api.github.com/repos/vercel/swr",
fetcher
);
return <></>
}
When saving the file I get the following message:
2
Answers
The issue gets solved by adding
"use client";
at the top.Refer to: https://swr.vercel.app/docs/with-nextjs
you are using Next.js 13.4.9. However, the latest version of SWR is 1.2.3, which is compatible with Next.js 13.4.9. So, you can update SWR to the latest version without any problems.
Once you have updated SWR, you should no longer get the error.