【发布时间】:2017-09-22 00:42:53
【问题描述】:
我的react-native 应用程序中有很多字符串。我看到一些字符串在多个地方使用。 IMO 我不想在我的代码中硬编码字符串,因为这不是好方法。如果项目规模较大,可能需要很长时间才能在多个位置更改相同的字符串。
什么方法是声明反应本机应用程序的字符串。我在有strings.xml的地方做android开发
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="string_name"
>text_string</string>
</resources>
我在 JS 文件中做什么。
<Text style={{ fontSize: 22, textAlign: "center" }}>
Never forget to stay in touch with the people that matter to you.
</Text>
【问题讨论】:
-
你可以有一个常量对象,你可以在任何需要这些字符串的地方导入
-
@MotiAzu 你能用sn-p的代码解释一下吗?
标签: android string react-native