我是 React Native 的初学者,在我的项目中,我在按下按钮用户名和身份验证状态后没有初始化我的变量,但在第二次按下后我的状态初始化并显示数据可以帮助我解决这个问题。谢谢
const DataFeatch = async () => {
await Authentication_Creator();
let SearchData = {
"user_name": await UserName,
"user_authentication": await User_Authentication,
};
try {
let response = await fetch('fechURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(SearchData),
});
let json = await response.json();
if (json == 'no result') {
something
} else {
SetDataSource(json);
}
}
catch{
ERRoR
}
}
我的 Authentication_Creator 是
const Authentication_Creator = async () => {
var RNFS = require('react-native-fs');
var path = RNFS.DocumentDirectoryPath + 'path';
var data = await RNFS.readFile(path, 'utf8');
var mydata = await JSON.parse(data);
let hash = data;
hash = md5(hash);
SetUserName(() => mydata.UserName);
SetUser_Authentication(() => hash);
}
宝慕林4294392
相关分类