缺少mapStateToProps中的道具

时间:2017-04-27 18:59:52

标签: react-router react-redux react-apollo

4.1.1

重现的步骤

由于Apollo,该组件通过GraphQL查询数据库。它是一个GraphQL容器。 它使用compose库中的react-apollo,以便以可读的方式同时使用multiple enhanchers

示例组件:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { graphql, compose, withApollo } from 'react-apollo';
import { myQuery } from './graphqlQuery';

class MyComponent extends Component {
  render() {
    const { exampleProp } = this.props;
    return null;
  }
}

function mapStateToProps(state, ownProps) {
  // I expect to see ownProps.exampleProp here but it is undefined
  console.log(ownProps.exampleProp);
}

export default compose(
  withApollo,
  connect(mapStateToProps),
  graphql(myQuery),
)(MyComponent);

预期行为

ownProps应包含传递给组件as stated here的道具 像:

Object = {
  client: ApolloClient
  exampleProp: "propcontent",  // <-- this is going to be lost
  history: Object
  location: Object
  match: Object
  staticContext: undefined
  __proto__: Object
}

实际行为

而ownProps只包含这个:

Object = {
  client: ApolloClient
  history: Object
  location: Object
  match: Object
  staticContext: undefined
  __proto__: Object
}

组件应该具有来自父项和GraphQL响应的所有道具,但在这种情况下包括exampleProp

0 个答案:

没有答案