【发布时间】:2018-11-11 05:09:05
【问题描述】:
我的组件需要调用 graphql 查询,但它需要只能由 redux 使用的变量。所以我已经映射了 redux 的连接来响应 apollo compose。但我在从 reducer 获取数据时遇到问题,并且调用未正确加载。
class abc extends Component {
componentWillMount() {
console.log(this.props.variableData); // Getting empty object.
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ variableDataFetchAction }, dispatch);
}
function mapStateToProps(state) {
return {
variableData: state.reducerName.variableData,
}
}
export default compose(
connect(mapStateToProps, mapDispatchToProps),
graphql(MyQuery, {
options: props => {
return {
.....,
variables: props.variableData,
};
},
}),
)(abc);
我需要知道我可以还原的方式是否有问题。因为我的商店似乎是空的。
【问题讨论】:
-
我想你混合了连接和撰写
-
我正在使用 react-apollo 中的 compose 并在 compose 中使用 redux connect 以便它首先执行然后加载查询数据。
-
好的。您介意用codesandbox.io 或类似的方式指定您的代码吗
-
好像有多余的右括号
标签: react-native redux react-redux redux-thunk react-apollo