79665473

Date: 2025-06-13 23:50:46
Score: 1
Natty:
Report link

Now could be used SWR in place of useEffect:

from https://nextjs.org/docs/pages/building-your-application/data-fetching/client-side

npm i swr
import useSWR from 'swr'
 
const fetcher = (...args) => fetch(...args).then((res) => res.json())
 
function Profile() {
  const { data, error } = useSWR('/api/profile-data', fetcher)
 
  if (error) return <div>Failed to load</div>
  if (!data) return <div>Loading...</div>
 
  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.bio}</p>
    </div>
  )
}
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Stéphane