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

javascript - Cannot read property 'skip' of undefined - Stack Overflow

programmeradmin2浏览0评论

I am using react-apollo for graphql query. I want to show a single object for category so for that I need an id which I can get from navigation.state.params.id. I did the following but I am getting an error of "Cannot read property 'skip' of undefined " . How should I solve this issue?

Here is my code

class CategoryDetail extends React.PureComponent {
  render() {
    console.log("props in detail", this.props);
    return (
      <View style={{ flex: 1 }}>
        <Text>Category View</Text>
      </View>
    );
  }
}

const CATEGORY_DETAIL_QUERY = gql`
  query CATEGORY_DETAIL_QUERY($id: ID!) {
    category(id: $id) {
      id
      name
    }
  }
`;

export default graphql(CATEGORY_DETAIL_QUERY, {
  options: props => {
    variables: {
      id: props.navigation.state.params.id;
    }
  },
})(CategoryDetail);

I am using react-apollo for graphql query. I want to show a single object for category so for that I need an id which I can get from navigation.state.params.id. I did the following but I am getting an error of "Cannot read property 'skip' of undefined " . How should I solve this issue?

Here is my code

class CategoryDetail extends React.PureComponent {
  render() {
    console.log("props in detail", this.props);
    return (
      <View style={{ flex: 1 }}>
        <Text>Category View</Text>
      </View>
    );
  }
}

const CATEGORY_DETAIL_QUERY = gql`
  query CATEGORY_DETAIL_QUERY($id: ID!) {
    category(id: $id) {
      id
      name
    }
  }
`;

export default graphql(CATEGORY_DETAIL_QUERY, {
  options: props => {
    variables: {
      id: props.navigation.state.params.id;
    }
  },
})(CategoryDetail);
Share Improve this question asked Nov 8, 2017 at 9:40 SerenitySerenity 4,0648 gold badges49 silver badges98 bronze badges 2
  • Can you tell us in what file and on what line this error occurs? – Tvde1 Commented Nov 8, 2017 at 9:51
  • TypeError: Cannot read property 'skip' of undefined This error is located at: in Apollo(CategoryDetail) (at SceneView.js:32) – Serenity Commented Nov 8, 2017 at 9:53
Add a ment  | 

1 Answer 1

Reset to default 4

Skip is one of the options Apollo checks. In your code, the options function is not returning anything.

Arrow functions return what is after => unless it is a {} block, in which case the return is to be defined inside the declared function body. If you want to return an object, which shares the same syntax as a code block, you need to wrap it inside ().

options: props => ({ variables: ... })
发布评论

评论列表(0)

  1. 暂无评论