【问题标题】:Shopify ResourcePicker not displayedShopify ResourcePicker 未显示
【发布时间】:2019-01-03 21:25:10
【问题描述】:

Polaris ResourcePicker 组件在我的嵌入式应用程序中根本没有显示,我不知道为什么。这是我的代码:

import React from "react";
import ReactDom from "react-dom";
import * as PropTypes from 'prop-types';

const session     = require('express-session');

import {AppProvider, Page } from '@shopify/polaris';
import {ResourcePicker} from '@shopify/app-bridge/actions';

class ExchangeApp extends React.Component {
  // This line is very important! It tells React to attach the `easdk`
  // object to `this.context` within your component.
  static contextTypes = {
    easdk: PropTypes.object,
  }; 

  state = {
    resourcePickerOpen: true,
  };

  render() {
    return <ResourcePicker
      resourceType="Product"
      open={this.state.resourcePickerOpen}
      onSelection={({selection}) => {
        console.log('Selected products: ', selection);
        this.setState({resourcePickerOpen: false});
      }}
      onCancel={() => this.setState({resourcePickerOpen: false})}
    />;
  }
}

ReactDom.render(
    <AppProvider apiKey="532cc1c7fa852e9bbf61c71bcbaa5a74">
      <ExchangeApp />
    </AppProvider>,
    document.querySelector('#root'),
  );

在浏览器的控制台中,我收到以下错误:

main.js:3584 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Check the render method of `ExchangeApp`.
at invariant (main.js:3584)
at createFiberFromTypeAndProps (main.js:13629)
at createFiberFromElement (main.js:13650)
at reconcileSingleElement (main.js:17327)
at reconcileChildFibers (main.js:17384)
at reconcileChildren (main.js:17753)
at finishClassComponent (main.js:18080)
at updateClassComponent (main.js:18018)
at beginWork (main.js:18864)
at performUnitOfWork (main.js:21679)

非常感谢您的帮助!

【问题讨论】:

    标签: shopify shopify-app polaris


    【解决方案1】:

    从 @shopify/polaris 导入 ResourcePicker 不是从 easdk。

    您的渲染返回也需要用括号括起来

    return (<ResourcePicker.../>);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 1970-01-01
      相关资源
      最近更新 更多