获取错误_reactApollo.connect(0,mapQueriesToProps)不是函数

时间:2017-09-15 10:16:31

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

我正在使用react-apollo客户端和ApolloProvider连接我的组件与queryprops函数来呈现数据但是我得到这个错误undefined不是一个函数(评估(_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);

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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