How do I convert a string to jsx?

前端 未结 8 1975
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:44

    I came across this answer recently and, it was a good deal for me. You don't need to provide a string. Returning an array of JSX elements will do the trick.

    We can store JSX elements in JavaScript array.

    let arrUsers = [
  • Steve
  • ,
  • Bob
  • ,
  • Michael
  • ];

    and in your HTML (JSX) bind it like,

      {arrUsers}

    As simple as it is.

提交回复
热议问题