我想使用异步存储.每次我调用时不使用异步函数,如下所示
FunctionLogin = () =>{ //other methods here ........ }
个
它没有在任何地方等待,它会保存到数据库中,但当我使用let Email=AsyncStorage.getItem(‘Email’)回调它时,它不会返回任何类似于邮箱的内容,只是我看到的是[Object Object
我该如何解决这个问题?
保存到异步存储的FETCH方法如下所示
`FunctionLogin = async () =>{
//navigation.replace('VirtualAccountPage');
let item = {email, password,phone};
fetch('https://xxxxxxxxxxxxxxxx/api/sign-up', {
method: 'POST',
mode: 'cors',
headers: {
Accept: 'application/json',
'Content-type': 'application/json',
},
body: JSON.stringify(item),
})
.then(response => response.json())
.then(responseJson =>{
if (responseJson.message === 'User created Successfully') {
await AsyncStorage.setItem('email', email);
await AsyncStorage.setItem('phone', phone);
alert('I am Registered');
navigation.replace('VirtualAccountPage');
} else {
alert(responseJson);
}
})
.catch(error => {
console.error(error);
});
}`
回调它的函数,因此它可以用作持久化,如下所示
` FunctionUserDetails = () => {
let email = AsyncStorage.getItem('email');
let phone = AsyncStorage.getItem('telephone');
//navigation.replace('Dashboard');
alert(email);
};`
我怎么才能让它起作用呢?
我希望能够保存数据本地使用异步存储,这样我就可以持久的一些其他屏幕上的数据等.我try 了几件事,看看它是否可以像预期的那样工作,我没有看到它的工作方式,我想.