我相信您需要对选项使用箭头功能
const somethingQuery = gql`query getSomething {
something(id:$id) {
name
}
}`
const somethingWithData = graphql(somethingQuery, {
options: (ownProps) => {
variables: {
id: ownProps.params.id
}
}
})(Something)
export default somethingWithData
另外,对我来说,参数可以在 props.match 中找到,所以它看起来像这样(在 React Router 4 中)。哦,我还将($id: ID!)
参数传递给查询
const somethingQuery = gql`query getSomething($id: ID!) {
something(id:$id) {
name
}
}`
const somethingWithData = graphql(somethingQuery, {
options: (ownProps) => {
variables: {
id: ownProps.match.params.id
}
}
})(Something)
export default somethingWithData