0

I want to print currency symbol from its currency code.
but it not working from variable.

My Code:-

render() {
  var currencyCode = "$"
  return (
      <View>
        <Text>{currencyCode}</Text>
        <Text>&#36;</Text>
      </View>
  )
}

Output:- enter image description here

if enter static currency code so it is working but not working from variable.

How to print currency symbol from variable?

Bhaumik Surani
  • 1,730
  • 3
  • 19
  • 40
  • 1
    Possible duplicate of [React app rendering html entities such as ampersand as escaped](https://stackoverflow.com/questions/52467082/react-app-rendering-html-entities-such-as-ampersand-as-escaped) – Estus Flask Oct 09 '18 at 08:25
  • above link for webpage but i'm using react native mobile application – Bhaumik Surani Oct 09 '18 at 08:31
  • See [Render HTML in React Native](https://stackoverflow.com/questions/29334984/render-html-in-react-native) – Gabriele Petrioli Oct 09 '18 at 08:36
  • The answer in dupe question explains all options. There are three of them. If you can't use dangerouslysetinnerhtml in React Native then you have only two. – Estus Flask Oct 09 '18 at 08:40

2 Answers2

1

This similar question explains all available options. Since dangerouslySetInnerHTML is inapplicable in React Native, there are only two of them.

HTML entities can be specifically decoded, e.g. with html-entities:

import { Html5Entities } from 'html-entities';
const htmlEntities = new Html5Entities();

...

{htmlEntities.decode(htmlString)}

The problem can be avoided by not storing HTML entities in the first place if possible. Currency symbols are valid Unicode characters and can be stored as such:

var currencyCode = "€"; // &#8364;
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
0

Think you should use unicoded symbols as shown in this tutorial

seclace
  • 98
  • 7