【问题标题】:Getting error _reactApollo.connect(0, mapQueriesToProps) is not a function收到错误 _reactApollo.connect(0, mapQueriesToProps) 不是函数
【发布时间】:2018-02-24 12:09:08
【问题描述】:

我正在使用 react-apollo 客户端和 ApolloProvider 将我的组件与 queryprops 函数连接以呈现数据,但我收到此错误 undefined is not a function(evaluating(_reactApollo.connect)(mapQueriesToProps))

import React, { Component } from 'react';
import { connect, gql, graphql } from 'react-apollo';
import { View, Text, ActivityIndicator } from 'react-native';

class ProductsScreen extends Component {

    componentWillMount() {
        console.log('component is going to render');
    }

    renderProducts() {
        if (this.props.data.loading) {
            return (
                <View>
                    <ActivityIndicator size='large' />
                </View>
            );
        }

        return (
            <Text>{ this.props.data.shop.name }</Text>
        );
    }

    render() {
        return (
            <View>
              { this.renderProducts() }
            </View>
        );
    }
}

const mapQueriesToProps = ({ ownProps, state }) => {
  return {
            query: gql`query {
                  shop {
                      name
                      primaryDomain {
                        url
                        host
                      }
                    }
             }`
        };
};

export default connect(mapQueriesToProps)(ProductsScreen);

【问题讨论】:

标签: react-native react-redux react-apollo apollo-client


【解决方案1】:

你应该导入gql from 'graphql-tag' 查看迁移文档https://www.apollographql.com/docs/react/2.0-migration.html

【讨论】:

    【解决方案2】:

    我不知道为什么 react apollo 的连接功能不起作用。 所以我通过调用 graphql 函数而不是 connect 函数解决了这个问题,并将 myQuery 作为参数传递。像这样:

    导出默认graphql(myQuery)(MyComponent);

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 2018-06-14
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多