question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Equivalent dangerouslySetInnerHTML?

See original GitHub issue

I’m having trouble using UTF-8 entities in <Text> elements. For example, the following will work as expected:

<Text>&#174;</Text>

But this will not:

var txt = '&#174;';
return <Text>{txt}</Text>

I’m assuming it’s because variables get escaped at some point - is there an equivalent dangerouslySetInnerHTML for Text components?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
nicklockwoodcommented, Apr 25, 2015

We don’t use HTML for rich text on the native side at all. I suspect (although I’m not 100% sure) that the reason the first example works is that the JSX parser converts the entity into the equivalent unicode character.

So to make the second example work, you should probably use JavaScript-style unicode escaping instead of XML/HTML-style escaping - i.e.

var txt = '\u00AE';
return <Text>{txt}</Text>
2reactions
ericyang89commented, Dec 6, 2017

I meet the same problem,any one have solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safe alternative to dangerouslySetInnerHTML - Stack Overflow
Alternative 1: Rewrite your app to pass data to components instead · Alternative 2: Don't write your own page builder · Alternative 3...
Read more >
Using dangerouslySetInnerHTML - Getting Started with DOM
This article will discuss dangerouslySetInnerHTML in React and how it ... There isn't a prebuilt alternative to the dangerouslySetInnerHTML ...
Read more >
Using dangerouslySetInnerHTML in a React application
This article covers the reasoning behind using the dangerouslySetInnerHTML property in a React application, which is the equivalent of the ...
Read more >
Dangerously set innerHTML alternative | remarkablemark
An alternative to React's dangerouslySetInnerHTML is html-react-parser, which converts an HTML string to React elements.
Read more >
DangerouslySetInnerHTML in React JS Explained
dangerouslySetInnerHTML is an attribute under DOM elements in React. According to the official documentation, dangerouslySetInnerHTML is React's replacement ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found