嗯,例如我有容器和api:
容器:
...
const mapDispatchToProps = dispatch => ({
handleSubmitForm: (signin_data) => {
dispatch(getUserInfo(signin_data))
}
})
...
API:
...
export function logIn( data ){
return dispatch => {
dispatch(startFetching('signin'))
return axios.post(domain + '/signin', {user: data})
.then(response => {
setTokensToLocalStorage( response.data )
dispatch(fetchingSuccess('signin'))
dispatch(getCurrentUser())
hashHistory.push('/')
dispatch(callFlash('success', 'signIn'))})
.catch(error => {
dispatch(fetchingFailed('signin'))
dispatch(callFlash('error', 'signInFail'))})
}}
/some simple functions for logout, signup etc/
...
似乎应该是这样的:
...
export function logIn( data ){
return dispatch => {
dispatch(startFetching('signin'))
return axios.post(domain + '/signin', {user: data})
.then(response => {
dispatch(fetchingSuccess('signin'))})
.catch(error => {
dispatch(fetchingFailed('signin'))})
}}
/some simple functions for logout, signup etc/
...
但是我应该在哪个地方调用其他方法?可能在容器中,但是在每个容器中导入这个方法会很奇怪,因为我只能在api中导入它们一次
dispatch(getCurrentUser())
hashHistory.push('/')
dispatch(callFlash('success', 'signIn'))
dispatch(callFlash('error', 'signInFail'))