how to parse " in react native

Viewed 1491

I am fetching some data from API and it is returning me results like " how can I convert it to normal form ' " '

const results = [
  { question: ' movie "The Revenant"?' },
  { question: ' game "Roblox" released?' },
  { question: '"A rainy Lithuanian / Is dancing as an Indian"' },
];

export default function App() {
  return (
    <View style={styles.container}>
      {results.map((q) => (
        <Text> {q.question} </Text>
      ))}
    </View>
  );
}

this is what I am getting

enter image description here

2 Answers

one way you can use replace in client side like that :

  • .replace(/&quot;/g, '"')

or other way you can save quot in database and send from backend side like format:

  • question: ' movie '''The Revenant'''?'

I hope that's Helpful

There isn't a built in way in javascript as far as I know. I have used the he library in the past to make it easy, this might suit you.

Best way is probably just through a string replace as mentioned in other answer. Full list of html character entities found here.

Barring that, you can always add an element to the dom and set the inner html but this can be dangerous as it can introduce XSS vulnerabilities as you can inject javacript code this way.

Related