将变量传递给突变组件-react-apollo

时间:2019-11-12 13:12:36

标签: reactjs react-apollo

我有这些突变方法,我想折光它,以便突变成分接受变量props。在这种情况下,将组件安装为参数时可以使用它们。

所以目前这些是我拥有的方法:

  handleInterestClick = (registerInterest: MutationFn) =>
  async () => {
    const { match: { params: { idea } } } = this.props;
    const result = await registerInterest({
      variables: {
        ideaId: idea,
      },
    });

    const { data: { registerInterest: { error } } } = result;
    if (error) {
      throw {
        type: 'RegisterInterest',
        error,
      };
    }
    return this.closeModal();
  }

  renderAdditionInterestCTA = () => {
    return (
      <Mutation mutation={REGISTER_INTEREST}>
        {(registerInterest: MutationFn) => {
          const handleClick = this.handleAdditionInterestClick(registerInterest);
          return (
            <ModalButton onClick={handleClick} context="primary">{i18n.t('client.apps.interest.cta')}</ModalButton>
          );
        }}
      </Mutation>
    );
  };

如果我要将变量传递给突变组件,它会像这样<Mutation mutation={REGISTER_INTEREST} variables={{ ideaId: idea}}>吗?以及如何折射handleInterestClick

0 个答案:

没有答案