File size: 596 Bytes
fc04d53 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 'use client';
import { useEffect } from 'react';
interface JsonLdScriptsProps {
schemas: object[];
}
export function JsonLdScripts({ schemas }: JsonLdScriptsProps) {
useEffect(() => {
const nodes: HTMLScriptElement[] = schemas.map((schema, i) => {
const el = document.createElement('script');
el.type = 'application/ld+json';
el.id = `json-ld-${i}`;
el.textContent = JSON.stringify(schema);
document.head.appendChild(el);
return el;
});
return () => {
for (const node of nodes) node.remove();
};
}, [schemas]);
return null;
}
|