react native currency symbol not printing from variable

巧了我就是萌 提交于 2019-12-31 07:04:14

问题


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:-

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

How to print currency symbol from variable?


回答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;



回答2:


Think you should use unicoded symbols as shown in this tutorial



来源:https://stackoverflow.com/questions/52716366/react-native-currency-symbol-not-printing-from-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!