当我们移动到屏幕时,异步存储尚不清楚 iOS React Native

async storage is not clear when we move to screen ios react native

提问人:kartikay dwivedi 提问时间:11/9/2023 最后编辑:Rory McCrossankartikay dwivedi 更新时间:11/9/2023 访问量:24

问:

我有一个函数,可以在点击结帐时调用。它必须从异步存储中删除并移动到主屏幕。移动到主屏幕然后移动到购物车屏幕后,它仍然具有异步存储,但是当我刷新时,异步存储被清除了?completeCartcart_IdcartId

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
  }
};
JavaScript iOS React-Native 异步存储

评论

1赞 kartikay dwivedi 11/9/2023
对不起,我这边的标签不小心打开了,我忘了看到这个,无意骑车

答: 暂无答案