Skip to content Skip to sidebar Skip to footer

Render Formatted (unminified) Html In React (ssr With Next.js)

How can I render formatted (unminified) HTML in React (SSR with Next.js)? Expected output:

Solution 1:

You need to format the output before actually returning to browser. So as for nextjs, first switch to the custom server nexjs custom server and routing and walkthrough this answer for pretty printing html. Using nextjs or react SSR, this may not be possible as a built-in configurable option.

Solution 2:

You might be looking for dangerouslysetinnerhtml. It allows you to pass in a string that you want rendered as raw HTML.

functioncreateMarkup() {
  return {__html: '<div><div><input type="text"/></div></div>'};
}

functionMyComponent() {
  return<divdangerouslySetInnerHTML={createMarkup()} />;
}

Post a Comment for "Render Formatted (unminified) Html In React (ssr With Next.js)"