Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SWR – Uncaught TypeError: Cannot read properties of undefined

I’m trying to use SWR for fetching data but I’m getting this error. Not sure why this is happening, though it works fine with use effect hook.

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the json data where it is fetching from –

{
  "dashboards": {
    "posts": 5,
    "likes": 5,
    "followers": 5,
    "followings": 5
  }
}

>Solution :

Use optional chaining see if that works:

<p>
{data?.posts}
</p>
<p>
{data?.likes}
</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading