How to render a string with JSX in React

前端 未结 1 1711
悲&欢浪女
悲&欢浪女 2020-12-10 05:27

I need to render an HTML (JSX) string in a React class. I don\'t know if this is possible or not. dangerouslySetInnerHTML is not valid for me because I have differe

相关标签:
1条回答
  • 2020-12-10 05:51

    You can use babel to transform it

    npm install --save babel-core
    

    Then in your code

    var babel = require('babel-core');
    var Component = eval(babel.transform('<div><MyComponent /></div>').code);
    

    Please note that it is generally a bad idea to convert strings to executable code.

    0 讨论(0)
提交回复
热议问题