0

Given the following object which is being returned from a backend db table:

let a = {
  id: 1,
  menu_icon: "<AssessmentIcon />"
}

how can I remove the double quotes around "<AssessmentIcon />" which is a material-ui icon ?

I just need this to be <AssessmentIcon /> - no double quotes.

I have tried a.menu_icon.slice(1, -1) but this removes the actual tags < and >

ArthurJ
  • 777
  • 1
  • 14
  • 39
  • Unsure how this `Dynamic tag name in jsx and React` question is relevant to mine? – ArthurJ Aug 12 '21 at 00:23
  • You can't achieve this by manipulating the string, at least not without using eval(). You'll need a lookup table { '': () => }, for example. – shuckster Aug 12 '21 at 00:24
  • The quotes are just there to define the object as a string. They will not be in the string result. Do you actually just not want it to be a string in the first place? – Adam Harte Aug 12 '21 at 00:25
  • @AdamHarte - correct. if I can make it not be a string that is retrieved from the backend db, that should solve my problem. – ArthurJ Aug 12 '21 at 00:27
  • 1
    Will this work? `const e = React.createElement(a.menu_icon.replace(/(\W)/g,''));` – Steve Aug 12 '21 at 00:45

0 Answers0