提问人:kartikay dwivedi 提问时间:11/9/2023 最后编辑:Rory McCrossankartikay dwivedi 更新时间:11/9/2023 访问量:24
当我们移动到屏幕时,异步存储尚不清楚 iOS React Native
async storage is not clear when we move to screen ios react native
问:
我有一个函数,可以在点击结帐时调用。它必须从异步存储中删除并移动到主屏幕。移动到主屏幕然后移动到购物车屏幕后,它仍然具有异步存储,但是当我刷新时,异步存储被清除了?completeCart
cart_Id
cartId
const completeCart = async() => {
try {
const cartId = await AsyncStorage.getItem('cart_id');
const response = await fetch(`${BASE_URL}/store/carts/${cartId}/complete`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// Include other headers such as Authorization if required
},
}, );
if (!response.ok) {
const text = await response.text();
throw new Error(`HTTP error! Status: ${response.status}, Body: ${text}`, );
}
await AsyncStorage.removeItem('cart_id');
Alert.alert('Order created successfully ');
navigation.navigate(SCREENS.HOME);
} catch (error) {
console.error('Error completing cart:', error);
// Handle the error, e.g., show an alert to the user
}
};
答: 暂无答案
评论