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