Tushita Patel
Tushita Patel

Reputation: 21

Using html entity &nbsp in react hyperscript

I am trying to do something like

h(Modal.Title, " ") where h is the react-hyperscript method used in javascript.

I want that the html renders

<span class="abc">&nbsp;</span>

But it is actually doing:

<span class="abc">&amp;nbsp;</span>

Upvotes: 2

Views: 405

Answers (1)

Rob Johansen
Rob Johansen

Reputation: 5164

In order to render HTML entities, or any raw HTML for that matter, you need to use React's dangerouslySetInnerHTML property:

h(Modal.Title, {dangerouslySetInnerHTML: {__html: "&nbsp;"}})

Read more about it in the React documentation here.

Upvotes: 1

Related Questions