Next.js Discord

Discord Forum

Rendering react to static markup for json LD

Unanswered
Exotic Shorthair posted this in #help-forum
Open in Discord
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:
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-essentials

in 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

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.