ristapk
ristapk

Reputation: 1372

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.

Upvotes: 17

Views: 15488

Answers (3)

sroumieux
sroumieux

Reputation: 131

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));

Upvotes: 10

Erin Geyer
Erin Geyer

Reputation: 12063

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);

Upvotes: 4

coreyward
coreyward

Reputation: 80041

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)

Upvotes: 19

Related Questions