Rendering react to static markup for json LD
Unanswered
Exotic Shorthair posted this in #help-forum
Exotic ShorthairOP
HI in my webpage I want to render some react content to html but nextjs doesn't let me:
in a server component:
in client component:
What is the nextjs preferred way to statically render react elements to html for usecases such as this (jsonLd)?
in a server component:
ReactServerComponentsError:
You're importing a component that imports react-dom/server. To fix it, render or return the content directly as a Server Component instead for perf and security.
Learn more: https://nextjs.org/docs/getting-started/react-essentialsin client component:
Error: Internal Error: do not use legacy react-dom/server APIs. If you encountered this error, please open an issue on the Next.js repo.What is the nextjs preferred way to statically render react elements to html for usecases such as this (jsonLd)?
5 Replies
for JSON+LD, have a look at what the docs suggest: https://nextjs.org/docs/app/building-your-application/optimizing/metadata#json-ld
Exotic ShorthairOP
I am doing that
In one of the fields I want to render html
For example an FAQ answer: "<span>this is my answer with a <a>link</a></span>". But I am using the answer also in the react code and I prefer not to write things twice, so thats Why I want to render the answer to html.
In the example in the docs, the thing I would want is if
product.description is a ReactElement, I want to render it to html and then put it in the jsonLD object.