javascript - 如何使用 React Native 和 AWS 确保每次都导入我的个人资料信息?
问题描述
我有一个 RN/Expo 应用程序。用户可以登录并按下抽屉(汉堡)按钮,并查看他们的个人资料信息。此信息是从 AWS 服务器中提取的,但对于信息是否呈现/显示,它确实是命中注定的。我希望它一直显示,但这似乎从来都不是保证。
下面是我的代码:
export function DrawerContent (props){
const [ firstName, getFirstName ] = useState('')
useEffect(() =>{
(async()=>{
const displayName = async () =>{
const real_response = await client_instance.get_user_info() //server function that calls user's info from the AWS server
getFirstName(
<Text style = {styles.title}>
{real_response.first_name} {real_response.last_name}
</Text>
)
}
displayName()
}
)
},
[],
)
... //在抽屉的return语句中,它应该在打开时呈现
<View style = {{marginLeft: width*0.021, flexDirection: 'column'}}>
<Title style = {styles.title}>{firstName}</Title>
</View>
编辑
//This is the final form
const displayName = async () =>{
const real_response = client_instance.get_user_info().then(response=>{
getFirstName(
<Text style = {styles.title}>
{response.first_name} {response.last_name}
</Text>
)
}
)
console.log('response is here', real_response)
}
编辑照片:
const [ imageData, getImageData ] = useState(null)
const displayPhoto = async () => {
const real_response = client_instance.download_profile_photo().then(response=>{
getImageData(
response.raw_data
)
console.log('photo is here=>',response )
}
)
}
displayPhoto()
<View>
{imageData && <Avatar.Image source={{uri:`data:image/jpg;base64,${imageData}`}}/>}
</View>
解决方案
您可以使用then解析返回的承诺,并在其中调用getFirstName方法。
client_instance.get_user_info().then(response => { // call getFirstName here });
推荐阅读
- php - PHP将图像从url复制到文件夹
- .net - x:Reference "" 不是属性 "IsVisible" 的有效值
- kotlin - Kotlin 允许在函数中定义数据类,为什么?
- java - java spring 2.0中如何配置jasypt?
- firebase - 用于 Flutter 桌面嵌入的 Firebase 身份验证插件
- javascript - 如何使用不同文件中的 Socket.IO 监听特定事件?
- angularjs - 在带有过滤器的 AngularJS 中使用 ng-repeat 打印表
- c++ - 使用 devenv 命令行构建 Visual Studio 解决方案
- python - python groupby 类别列创建新的计数列
- c# - 从数据访问层收集垃圾