当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript react-apollo.connect函数代码示例

本文整理汇总了TypeScript中react-apollo.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connect函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createMutation

      },
      forceFetch: true
    }
  };
};

const mapMutationsToProps = (p: any) => ({
  removePostMutation: (id: string) => {
    return createMutation(`
      mutation removePost($id: String) {
         removePost(id: $id)
      }`, { id });
  }
});

const mapDispatchToProps = (dispatch: IDispatch, ownProps: IProps) => ({
  removePost: (mutation: any) => {
    dispatch(ownProps.removePost(ownProps.postId, mutation));
  },
});

const depsToPropsMapper = (context: IContext, actions: IActions) => ({
  removePost: actions.posts.remove
});

export default composeAll<IProps>(
  compose(apolloContainer()),
  connect({ mapQueriesToProps, mapMutationsToProps, mapDispatchToProps }),
  useDeps(depsToPropsMapper) // -> not needed here
)(Post);
开发者ID:TribeMedia,项目名称:meteor-mantra-redux-graphql,代码行数:30,代码来源:post.ts

示例2: addComment

      return {
        mutation: gql`
        mutation addComment($postId: String, $comment: String) {
           addComment(postId: $postId, comment: $comment)
        }`,
        variables: {
          postId: postId,
          comment
        }
      };
    }
  };
};

const mapStateToProps = (state: IState) => {
  return {
    error: state.post.error
  };
};

export const mapDepsToProps = (context: IContext, actions: IActions ) => ({
  create: actions.comments.create,
  clearErrors: actions.general.clearErrors,
  context: () => context
});

export default composeAll<IProps>(
  connect({mapMutationsToProps, mapStateToProps}),
  useDeps(mapDepsToProps)
)(Component);
开发者ID:TribeMedia,项目名称:meteor-mantra-redux-graphql,代码行数:30,代码来源:create_comment.ts

示例3: mapQueriesToProps

import { compose, composeAll } from 'mantra-core';
import apolloContainer from './apollo';
import { connect } from 'react-apollo';

interface IProps {
  context: IContainerContext;
}

function mapQueriesToProps() {
  return {
    data: {
      query: gql`
          {
            posts {
             _id,
             title,
             content
           }
          }
        `,
      forceFetch: true
    }
  };
};

export default composeAll<{}>(
  compose(apolloContainer()),
  connect({ mapQueriesToProps })
  // useDeps() // -> not needed here
)(PostList);
开发者ID:TribeMedia,项目名称:meteor-mantra-redux-graphql,代码行数:30,代码来源:postlist.ts


注:本文中的react-apollo.connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。