I'm struggling to make SWR work in my code. Despite trying multiple examples, I can't seem to get it functioning properly. It's frustrating because the code looks fine and should work. I feel like I must be missing something simple.
Currently, I am working with a basic next.js app template.
In my index.js
file, I have the following setup;
import useSWR from 'swr'
export default function Home({ isConnected }) {
const { data, error } = useSWR('/api/')
return() //jsx here
}
When I start the development server, it notifies me that I can view the site at http://localhost:3000. However, when I debug and pause on the return line, both data
and error
variables are coming back as undefined. If I visit http://localhost:3000/api/
, I do receive well-formatted JSON data (interpreted as such by Firefox).