我正在构建一个 React 应用程序并使用 redux-thunk 进行异步操作。我有两个函数getActivities()
,createActivity()
我想在成功调用后者后调用前者。但是如果我把它放在它的块getActivities()
里面就不会被调用(这可以通过没有看到我放入的 console.log() 来证明)。下面是两个函数:then
createActivity()
getActivities()
export const getActivities = () => dispatch => {
console.log('again');
return axios.get(ENV.stravaAPI.athleteActivitiesBaseEndPoint, autHeaders)
.then(resp => {
dispatch({type: actions.GET_ACTIVITIES, activities: resp.data})
})
.catch(err => {
if(window.DEBUG)console.log(err);
})
};
export const createActivity = data => dispatch => {
dispatch(setLoadingElement('activityForm'));
return axios.post(URL, null, autHeaders)
.then(resp => {
if (resp.status === 201) {
dispatch(emptyModal());
}
// I WANT TO CALL getActivities() HERE
dispatch(unsetLoadingElement('activityForm'));
})
.catch(err => {
if(window.DEBUG) console.log(err.response.data.errors);
dispatch(unsetLoadingElement('activityForm'));
});
};
我怎样才能在另一个内部调用一个?