最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - In my remix Shopify app, the resource picker is throwing an error...how can I resolve this error? - Stack Overflow

programmeradmin4浏览0评论

I've tried importing the shopify resource picker from app bridge react and said it didnt exist so I am now trying to import it from app bridge actions library with only slightly more success. It is throwing an error saying "this.app.subscribe is not a function". How is this resolved?

here is my code:

import { ResourcePicker } from "@shopify/app-bridge/actions";
import { useAppBridge } from "@shopify/app-bridge-react";
const app = useAppBridge();
useEffect(() => {
    if (app) {
      resourcePicker = ResourcePicker.create(app, {
        resourceType: ResourcePicker.ResourceType.Product, // or 'Collection'
        options: {
          selectMultiple: true,
        },
      });

      resourcePicker.subscribe(
        ResourcePicker.Action.SELECT,
        (selection: any) => {
          console.log("selection: ", selection);
        },
      );
    }
  }, [app]);

  const openPicker = () => {
    if (resourcePicker) {
      resourcePicker.dispatch(ResourcePicker.Action.OPEN);
    }
  };

I've tried importing the shopify resource picker from app bridge react and said it didnt exist so I am now trying to import it from app bridge actions library with only slightly more success. It is throwing an error saying "this.app.subscribe is not a function". How is this resolved?

here is my code:

import { ResourcePicker } from "@shopify/app-bridge/actions";
import { useAppBridge } from "@shopify/app-bridge-react";
const app = useAppBridge();
useEffect(() => {
    if (app) {
      resourcePicker = ResourcePicker.create(app, {
        resourceType: ResourcePicker.ResourceType.Product, // or 'Collection'
        options: {
          selectMultiple: true,
        },
      });

      resourcePicker.subscribe(
        ResourcePicker.Action.SELECT,
        (selection: any) => {
          console.log("selection: ", selection);
        },
      );
    }
  }, [app]);

  const openPicker = () => {
    if (resourcePicker) {
      resourcePicker.dispatch(ResourcePicker.Action.OPEN);
    }
  };
Share Improve this question edited Mar 25 at 15:18 Drew Reese 204k18 gold badges245 silver badges273 bronze badges asked Mar 24 at 21:57 noahaclanoahacla 571 silver badge3 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you are using the legacy version, please check Example code.

import createApp from '@shopify/app-bridge';
import {ResourcePicker} from '@shopify/app-bridge/actions';

const app = createApp(config);

const productPicker = ResourcePicker.create(app, {
  resourceType: ResourcePicker.ResourceType.Product,
});

Also, I saw you are using legacy versions. I recommend upgrading to the latest version. Please check migration guide.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论