nextjs swr fetch data client side

nextjs swr fetch data client side

Fetching data on the client side? Use https://swr.now.sh/ by @zeithq. It handles caching, revalidation, focus tracking, refetching on interval, and more.

Copy Snippet
import useSWR from 'swr'

function Profile() {
  const { data, error } = useSWR('/api/user', fetch)

  if (error) return <div>failed to load</div>
  if (!data) return <div>loading...</div>
  return <div>hello {data.name}!</div>
}