【发布时间】:2017-03-16 13:31:35
【问题描述】:
这是我的行动:
export function fetchNearbyUsers(user, position) {
return (dispatch) => {
const query = new Parse.Query(Parse.User);
query.withinKilometers('location', createGeoPoint(position), 10);
query.equalTo('gender', user.attributes.interest);
query.notEqualTo('objectId', user.id);
query.limit(15);
return query.find().then((users) => {
dispatch({ type: GET_NEARBYUSER_LIST, payload: users });
return Promise.resolve();
}).catch((error) => {
});
};
}
现在的问题是,当我通过 connect 映射我的调度时,为什么返回未定义。
this.props.fetchNearbyUsers(this.props.user, this.props.location).then(() => {
this.setState({ refreshing: false });
}).catch((error) => {
});
const mapDispatchToProps = dispatch => ({
fetchNearbyUsers: (user, position) => {
dispatch(fetchNearbyUsers(user, position));
},
});
当我通过上下文访问商店时,这会返回 Promise:
const { dispatch } = this.context.store;
this.setState({ refreshing: true });
dispatch(fetchNearbyUsers(this.props.user, this.props.location)).then(() => {
this.setState({ refreshing: false });
});
【问题讨论】:
标签: javascript reactjs redux redux-thunk