Ciprian
Ciprian

Reputation: 3226

StencilJS display string as HTML

I need to display html elements based on a file type. The html element creates icons. Now I only get a string.

{
   isArray(data.Attachments)
   ?
   data.Attachments.map(attachment =>
     getIcon(attachment.FileExtension)
   )
   : ''
}

const getIcon = (icon: string): string => {
  if (icon) {
    return '<span class="icon-nolink video-link"></span>'
  }
}

Upvotes: 2

Views: 3203

Answers (1)

Thomas
Thomas

Reputation: 8849

To output unescaped HTML you can use the innerHTML attribute:

render() {
    return <div innerHTML={getIcon('name')}></div>
}

Source: https://stenciljs.com/docs/templating-jsx/#complex-template-content

Upvotes: 5

Related Questions