-
Summary
|--app
|----components
|----schema.js <----- ( we are here )
|----page.js
|----layout.js
import Script from 'next/script';
export const Schema = ({ schema = [] }) => {
const buildSchema = schema.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.someValue,
item: item.someUrl? item.someUrl: undefined
}));
return (
schema &&
schema.length !== 0 && (
<Script
id="some-next-level-schema"
strategy="beforeInteractive"
defer
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: `${JSON.stringify({
'@context': 'https://schema.org',
'@type': 'Some-NextLevel-Schema',
itemListElement: buildSchema
})}`
}}
/>
)
);
}; *** This is a Server Component ***
|--app
|----page.js <----- ( we are here )
import { Schema } from "@components/schema.js";
const MainComponent = () => {
const list = [
{ someValue: "John",
someUrl: "www.johndoe.com"
},
]
return <Schema schema={list}/>
};
export default MainComponent ; Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Answered by
S550Stang
May 22, 2024
Replies: 1 comment 14 replies
-
@icyJoseph Please Help |
Beta Was this translation helpful? Give feedback.
14 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks To @icyJoseph For Finding This Neat Nugget Hidden In The React Doc
FINALLY RENDERS INSIDE THE HEAD