本文整理匯總了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);
示例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);
示例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);