How do I convert a string to jsx?

前端 未结 8 1959
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:35

    You need to use babel with preset react

    npm install --save-dev babel-cli babel-preset-react
    

    Add the following line to your .babelrc file:

    {
      "presets": ["react"]
    }
    

    Then run

    ./node_modules/.bin/babel script.js --out-file script-compiled.js
    

    You can find more info here

提交回复
热议问题