Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native HTML entities

I'm fetching some data in app from WordPress site successfully. Some entities like "&#8222" react native don't want to make like quotes and many more issues I have.

Is there some way to make HTML entities right in React Native App?

Thanks in advance.

like image 276
ristapk Avatar asked May 08 '18 19:05

ristapk


3 Answers

I had the same problem. This is the way I solved it:

First of all install html-entities :

npm install html-entities

In your code :

import {decode} from 'html-entities';

console.log(decode(stringToBeDecoded));
like image 185
sroumieux Avatar answered Sep 23 '22 12:09

sroumieux


You should be able to use something like html-entities to decode the text before rendering:

const entities = new Entities();
entities.decode('&#8222') // "„" (double low quotation mark)
like image 18
coreyward Avatar answered Nov 18 '22 18:11

coreyward


Here's how to import and use a specific subpackage of Entities if the example in 'html-entities' README, which uses require(), won't work for you.

import {Html5Entities} from 'html-entities';

const entities = new Html5Entities();
entities.decode(stringToBeDecoded);
like image 4
Erin Geyer Avatar answered Nov 18 '22 17:11

Erin Geyer