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?
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!
Most helpful comment
Using
dangerouslySetInnerHTML