我的react + rails应用程序中有一个非常严重的行为: 当我从后端请求一些数据时,一切都按预期工作,直到我想在redux中存储这个对话时: Normal response with the conversation property
但是当我想将它存储在redux中时,对话属性在响应conversation missing in the response, how is this possible中是空的? 这就是我记录这个回复的行动:
const url = process.env.REACT_APP_API
export function getConversations(task, headers) {
console.log(headers)
return function(dispatch) {
console.log('task:', task)
const path = `tasks/${task}`
axios
.get(url + path, headers)
.then(response => {
console.log(response)
dispatch({
type: GET_CONVERSATIONS,
payload: response.data.data,
})
})
那就是我的减速器,它足以删除减速器中的一个字母,我开始得到正确的回复,如邮递员所示:
const InitialConversations = []
export default function conversations(state = InitialConversations, action) {
switch (action.type) {
case GET_CONVERSATIONS:
return action.payload.conversations
default:
return state
}
}
我这样称呼它:
constructor(props) {
super(props)
this.state = {
activeIndex: Number(this.props.match.params.id),
}}
componentWillMount() {
this.props.getConversations(this.state.activeIndex, this.props.headers)
}