Next.js: JSON-LD

Created on 9 Jun 2017  路  2Comments  路  Source: vercel/next.js

I want add structured data to head via json-ld:
<script type="application/ld+json"> { { "@context": "http://schema.org", "@type": "LocalBusiness", ... } } </script>
But I have error:
Invariant Violation: Objects are not valid as a React child (found: object with keys {@context, @type, address, image, description, name, priceRange, telephone, openingHours, url, logo, email, hasMap, geo, sameAs}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons.
How can I avoid render's this object?

Most helpful comment

Using dangerouslySetInnerHTML

<script type='application/ld+json' dangerouslySetInnerHTML={ { __html: `{ "@context": "http://schema.org", "@type": "LocalBusiness", ... }`}} />

All 2 comments

Using dangerouslySetInnerHTML

<script type='application/ld+json' dangerouslySetInnerHTML={ { __html: `{ "@context": "http://schema.org", "@type": "LocalBusiness", ... }`}} />

cautionary tale: i tried to render some json+ld like a normal string, eg:
```

``` it appeared to work perfectly on my site, when google scraped it, all quotes were transformed to"` & none of the data was parsed.

glad i found this issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knipferrc picture knipferrc  路  3Comments

irrigator picture irrigator  路  3Comments

rauchg picture rauchg  路  3Comments

wagerfield picture wagerfield  路  3Comments

YarivGilad picture YarivGilad  路  3Comments