Display TinyMCE Content in React
Asked Answered
A

3

5

As per title, what I'm trying to achieve is to display the Wysiwyg content from the Editor to another component.

I created a sample on codesandbox here: https://codesandbox.io/s/boring-tharp-zwflu

As you can see, the editor works fine and is returning the values as it should.

My issue here is I'm not able to convert that String I get returned, into JSX tags.

I did a deep search, but couldn't find anything related.

Thank you in advance for your time and help!

Anhydrous answered 25/5, 2020 at 12:3 Comment(1)
i need answer too, wasted my whole day searching for thisVenator
B
6

You have to install npm i react-html-parser import it to your component import ReactHtmlParser from "react-html-parser";"; and render it

<div className="wysiwyg">
{ReactHtmlParser(wysiwyg)}
</div>
Brendonbrenk answered 20/7, 2020 at 4:58 Comment(1)
Hi Anna, at the end I've been able to find the solution (which you can see on the other answer) - But thank you anyway for the help :)Anhydrous
A
4

I actually found the solution at the end, sorry for not having updated it already!

Here the answer I got from TinyMCE for this issue: https://github.com/tinymce/tinymce-react/issues/138

So, you should use directly a parser, in this case react-html-parser will do the job.

I created another codesandbox so you can directly have a look at the working copy: https://codesandbox.io/s/crazy-greider-dl2mv

Hope that help!

Anhydrous answered 18/6, 2020 at 15:13 Comment(0)
J
1

Actually on 2023-10-02 is not working correctly something is with dependencies (last relies is 6 years ago) so anyone who read this use html-react-parser instead.

Here is the dependency problem with react-html-parser discussed and found soulution Unable to resolve dependency for installing html-parser

Jennijennica answered 2/10, 2023 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.