Reputation: 65
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.
This is the json data where it is fetching from -
{
"dashboards": {
"posts": 5,
"likes": 5,
"followers": 5,
"followings": 5
}
}
Upvotes: 3
Views: 2581
Reputation: 2341
Use optional chaining
see if that works:
<p>
{data?.posts}
</p>
<p>
{data?.likes}
</p>
Upvotes: 2