| '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; | |
| } | |