I am not able to implement an icon on svg element inside the template literal in react . I get error like [object object].Next to the Other, i wanted to display an icon.Here is the image
Above is the code. If i remove the condition to check seriesName === ‘Other’ then i can easily load SVG but with that condition i am not able to load SVG inside template string. How do i fix it ?
2
Answers
it appears you’ve placed the backticks
``
at the wrong place.The back ticks should wrap around the SVG element you intend to render when the condition is truthy not your entire block of code.
Here’s the revised version of your code:
Backticks (“) are used for a string. When rendering a JSX/HTML element, backticks are not needed. By using backticks to wrap the entire span element, it renders the string of the span element (ie Other [object Object] ).
The object is an attempt to convert the object into a string. Instead, render the span element and the SVG directly.
Here is the revised code: