AppmakerDeveloper

useWishlistProductIds

This hook returns an array of product ids that are in the wishlist.

propsTypeDescription
productIdsArrayArray of product ids

Usage

import { runDataSource } from '@appmaker-xyz/core';
import { useWishlistProductIds } from '@appmaker-xyz/shopify';

 const WishTest = (props) => {
  const [products, setProducts] = React.useState([]);
  // Getting wishlisted product ids from hook.
  const { productIds } = useWishlistProductIds();
  const dataSource = {
    attributes: {},
    source: 'shopify',
  };
  useEffect(() => {
    getProducts();
  }, []);
  const getProducts = async () => {
    // getting products data from shopify using product id's.
    const [response] = await runDataSource(
      {
        dataSource,
      },
      {
        methodName: 'products',
        params: {
          ids: productIds,
        },
      },
    );
    if (response?.data?.data?.products?.edges?.length > 0) {
      setProducts(response.data.data.products.edges);
    }
  };

  const productsView = products?.map?.(({ node }) => <Text>{node.title}</Text>);

  return (
    <View>
      <Text> Wishlist component </Text>
      {productsView}
    </View>
  );
};

On this page