How do I convert a string to jsx?

前端 未结 8 2014
Happy的楠姐
Happy的楠姐 2020-11-27 20:19

How would I take a string, and convert it to jsx? For example, if I bring in a string from a textarea, how could I convert it to a React

8条回答
  •  广开言路
    2020-11-27 20:28

    I've been using html-to-react with some success (self closing tags cause a problem though, but a fix is in the pull requests...) to parse markup strings as DOM like objects, and in turn React elements. It's not pretty, and if you can avoid it, do so. But it gets the job done.

    html-to-react at github: https://github.com/mikenikles/html-to-react

提交回复
热议问题