HomeiOS Developmentjavascript - async storage just isn't clear after we transfer to display...

javascript – async storage just isn’t clear after we transfer to display screen ios react native


i’ve a whole cart operate which invokes on click on of checkout , it has to take away cart_ID FROM ASYNC STORAGE AND MOVE TO HOME_SCREEN , AFTER MOVING TO HOME-SCREEN THEN TO CART SCREEN IT STILL HAS CART_ID FROM ASYNC STORAGE BUT WHEN I REFRESH THEN ASYNC STORAGE IS CLEAR ?

const completeCart = async () => {
    strive {
      const cartId = await AsyncStorage.getItem('cart_id');
      const response = await fetch(
        `${BASE_URL}/retailer/carts/${cartId}/full`,
        {
          technique: 'POST',
          headers: {
            'Content material-Kind': 'software/json',
            // Embody different headers akin to Authorization if required
          },
        },
      );

      if (!response.okay) {
        const textual content = await response.textual content();
        throw new Error(
          `HTTP error! Standing: ${response.standing}, Physique: ${textual content}`,
        );
      }

     
      await AsyncStorage.removeItem('cart_id');
      Alert.alert('Order created efficiently ');
      navigation.navigate(SCREENS.HOME);
    } catch (error) {
      console.error('Error finishing cart:', error);
      // Deal with the error, e.g., present an alert to the consumer
    }
  };

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments