如何将GraphQL查询结果作为支持传递给另一个组件-react-apollo

时间:2020-05-14 21:25:12

标签: reactjs graphql apollo react-apollo

我有一个包装器,该包装器基于teamName参数向mongodb集合查询文档ID。我想将此文档ID传递给另一个组件。我不太确定如何做到这一点。这是我到目前为止的内容:

包装器:

import React, { Component } from 'react';
import { gql } from 'apollo-boost';
import { Query } from 'react-apollo';

export const GET_TEAM_REGISTRATION_ID = gql`
    query($teamName: String!) {
        getTeamRegistrationID(teamName: $teamName) {
            _id
        }
    }
`;

const withTeamRegistrationID = Component => props => {

    return (
        <Query query={GET_TEAM_REGISTRATION_ID}>
            {({ loading, data }) => {

                return (
                    <Component getTeamRegistrationIDLoading={loading} getTeamRegistrationID={data && data.getTeamRegistrationID} {...props} />
                );
            }}
        </Query>
    );
};

export default withTeamRegistrationID;

组件:

@withTeamRegistrationID
export class FormPlayerDetails extends Component {

    render() { 
        console.log(this.props); 
}

我有两个问题:1)如何在组件中传递teamName参数,以及2)如何将查询结果作为prop传递给另一个组件?我想做类似this.props.getTeamRegistrationID

的事情

0 个答案:

没有答案