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?

2 Answers 2

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) }}
/>
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.