react-native - React-Native Text 属性中的异步函数
问题描述
我有一个函数可以从AsyncStorage
.
const cloudCheck = async function() {
let cloud = await AsyncStorage.getItem('cloud');
cloud = cloud === 'true';
return cloud;
}
我想用它来做类似的事情,但是因为这是一个我不知道该怎么做的承诺:
<Text className={ cloudCheck == "this" ? "style1" : "stye2" }></Text>
谁能给我任何指导?
解决方案
你可以在生命周期方法中调用它componentDidUpdate
(你也可以,render
但最好避免它)生命周期方法,然后setState({ cloud })
之后,在你的render
你可以做这样的事情
const { cloud } = this.state;
....
<Text className={ cloud ? "style1" : "stye2" }></Text>
推荐阅读
- php - 意外的状态行:在 HttpURLConnection 上使用 getInputStream() 时出现 Y������
- python - 相同 Keras CNN 的不同预测
- java - 这里的注释是什么意思?
- git - 如何将分支内容移动到另一个存储库以保留历史记录并避免复制原始存储库的完整历史记录?
- docker - 容器之间的连接被拒绝
- firebase - 使用 Firestore 进行本地离线开发
- javascript - 外部可执行文件无法加载必要的文件
- python - python:如何在布尔逻辑中包含 0
- laravel - 获取 Laravel 中每个不同项目名称的最小值和最大值的集合项目
- javascript - 类型错误:尝试获取资源时出现网络错误