How to use with React HTML Parser? #1024
-
Hello, Remix community! I've been searching about the solution to use with The library is needed so we can customize/modify the parsed HTML elements into custom components. For a very simple job,
So using In the "Dynamic Route Params" section, when talking about "Render the HTML in the route", just right before "Creating Blog Posts", it said to do this: // ...
export default function PostSlug() {
const post = useLoaderData();
return (
<div dangerouslySetInnerHTML={{ __html: post.html }} />
);
} The example use import ReactHtmlParser from 'react-html-parser'
<section>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
<div>{ReactHtmlParser(post.html)}</div>
</section> But then hit an error, "Uncaught Exception!"
Posted about this on Twitter:
Then @remix_run replied to "re-export":
But it still doesn't work yet. Now it shows two errors:
In the end, we can still use the usual Or maybe there will be a Remix wrapper for this? Maybe I made a mistake in configuring it, so I would be grateful if there's a hint on how to resolve this. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
From the error that library is trying to do a dynamic require of th events package, this is not supported on client side code that’s why it works server side (and why you are the HTML) but it fails client side. The second error is because you named it .server.ts and tried to use it both server and client side, but in the client it doesn’t exists because you used the .server.ts extension. |
Beta Was this translation helpful? Give feedback.
-
Just found HTML to React parser that works on both the server (Node.js) and the client (browser) This workaround works with Remix out of the box without any visible issue 🎉 Could be a good suggestion alternative to |
Beta Was this translation helpful? Give feedback.
Just found
html-react-parser
that turn out...HTML to React parser that works on both the server (Node.js) and the client (browser)
This workaround works with Remix out of the box without any visible issue 🎉
Could be a good suggestion alternative to
dangerouslySetInnerHTML