0
我遇到問題,我的操作不會進入我的返回語句。我已經從我已經開發過的項目或多或少地複製了代碼,並知道它的工作原理。如果有任何redux主人,那裏的幫助將不勝感激。React-Redux操作不會發送到還原器
import * as types from '../Constants/Action_Types'
import axios from 'axios'
export function getSingleReport(){
console.log("in the action")
return function (dispatch) {
console.log("in the action return function")
axios.get('/api/report-single/57b3aba0aa676af0a3db6250').then((result) => dispatch({
type: types.GET_SINGLE_REPORT,
reportTitle: result.data.title,
reportAuthor: result.data.author
}))
}
}
我會打第一個conole.log聲明,但不是第二個。爲什麼行動決定停止在返回功能(dispatch){line?
按照要求,這裏還有減速機。
import { GET_SINGLE_REPORT } from '../Constants/Action_Types'
const initialState = {
reportTitle: "Title of Report",
reportAuthor: "Author of Report"
}
export default function populateReport(state = initialState, action) {
console.log("in the reducer")
switch (action.type) {
case GET_SINGLE_REPORT:
console.log("in the get GET_SINGLE_REPORT reducer")
return {
...state,
reportTitle: action.reportTitle,
reportAuthor: action.reportAuthor
}
default:
return state
}
}
沒有上下文,它是不可能的幫助。也許你沒有調用返回的函數? –
您是否配置了'redux-thunk'中間件?聽起來像這個項目沒有舊項目的適當中間件。 –
我確實配置了thunk中間件。第二個控制檯應在異步調用之前打印 – Peter3