2

I am trying to achieve something similar to this question How do I include a font awesome icon in my svg?

but I have 10 icons which has similar structure but only icon differs I have return a function to generate the Unicode character as

static renderIcon (status) {
    if (status === 'RED') {
      return ''
    } else if (status === 'GREEN') {
      return ''
    } else if (status === YELLOW') {
      return ''
    }
  }

static renderTextWithIcon = (obj) => {
    return (
        <text x={params.cx} y={params.cy}
         className={ css.color}
         >
          {Utils.renderStatusIconContent(obj.status)}
        </text>
        )
  }

But it renders the strings as '' if I try to give without quotes it accepts and shows the icon,but I have to repeat the same code for each color. How can I write a function which take the Unicode characters as parameters?

halfer
  • 19,824
  • 17
  • 99
  • 186
Geeky
  • 7,420
  • 2
  • 24
  • 50

2 Answers2

1

If I get you right, you need to use dangerouslySetInnerHTML so that your unicode characters will not be escaped.

<text x={params.cx} y={params.cy}
  className={ css.color}
  dangerouslySetInnerHTML={{__html: Utils.renderStatusIconContent(obj.status) }}
/>
pumbo
  • 3,646
  • 2
  • 25
  • 27
0

@AlexM Thanks for the solution but i solved this situation in a little different way I have done this as

 static iconObj = {
    Right: '\uf126',
    Wrong: '\uf121',
  };

and i was rendering it as

<text x={params.cx} y={yParam}
         dy=".25em"
         onClick={onClick}>
          {iconObj[color]}
        </text>

This solved my problem for now.

Geeky
  • 7,420
  • 2
  • 24
  • 50