我有這樣的代碼,返回一個thunk爲我的API從反應-Redux的形式調用的thunk提交處理
import { SUBSCRIBE_REQUEST, SUBSCRIBE_SUCCESS, SUBSCRIBE_FAILURE } from '../../constants'
export function subscribeUser (data) {
return (dispatch, getState, { axios }) => {
dispatch({ type: SUBSCRIBE_REQUEST })
return axios.get(`some/api/call`, data)
.then(res => {
dispatch({
type: SUBSCRIBE_SUCCESS,
payload: res.data
})
})
.catch(error => {
dispatch({
type: SUBSCRIBE_FAILURE,
payload: error,
error: true
})
})
}
}
我現在推行react-redux-form
和我如何OT上述與提交功能連接不清楚。從自己的文件,預計我通過在提交行動承諾:
class myForm extends React.Component {
handleSubmit (data) {
const { dispatch } = this.props
dispatch(actions.submit('user', somePromise))
}
基本上是這樣的:
dispatch(actions.submit('user', subscribeUser))
如何我可以提交處理程序連接我thunked API代碼?我已經看過redux-promise
作爲一種可能性,雖然我不清楚它會解決我的問題,並且還想保留現有的代碼庫,如果我可以工作。