How to provide multiple JSON-LD objects
masterTo include multiple JSON-LD datasets from a single component, you can return an array of objects from useJsonld.
Note on Safari Compatibility: Safari may log an error to the console when an array is used to describe multiple data objects. While the library functions correctly, it is recommended to use the @graph notation instead to avoid these console errors and ensure cleaner error logging in tools like Sentry.
// Using an array (Note: may cause Safari console errors)
useJsonld([
{
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: [/* ... */],
},
{
'@context': 'https://schema.org',
'@type': 'NewsArticle',
mainEntityOfPage: { /* ... */ },
},
]);
// Recommended approach to avoid Safari errors: Use @graph notation
useJsonld({
'@context': 'https://schema.org',
'@graph': [
{ '@type': 'BreadcrumbList', /* ... */ },
{ '@type': 'NewsArticle', /* ... */ },
]
});