使用组合减速机使用嵌套的redux减速机
我已经看了很多使用嵌套减缩器的例子,但是我遇到了一个非常奇怪的问题 我有以下初始状态:使用组合减速机使用嵌套的redux减速机,redux,react-redux,Redux,React Redux,我已经看了很多使用嵌套减缩器的例子,但是我遇到了一个非常奇怪的问题 我有以下初始状态: window.store=configureStore({ 滑块:{ mainImageIndex:0, pageNum:1, 每页:4,//根据提供的要求 }, });您必须检查的是您的操作包含哪些内容 它似乎包含了这样的东西 { type: 'SET_MAIN_IMAGE', mainImageIndex: { mainImageIndex: 2 }, } {
window.store=configureStore({
滑块:{
mainImageIndex:0,
pageNum:1,
每页:4,//根据提供的要求
},
});代码>您必须检查的是您的操作包含哪些内容
它似乎包含了这样的东西
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: {
mainImageIndex: 2
},
}
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: 2
}
你的减速机会像
1。第一步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
2。第二步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
3。第三步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
4。第四步
case 'SET_MAIN_IMAGE':
return {
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
你应该做什么
更改操作
有效负载以发送类似的内容
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: {
mainImageIndex: 2
},
}
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: 2
}
或者更好
{
type: 'SET_MAIN_IMAGE',
payload: {
mainImageIndex: 2,
}
}
然后在减速器中使用
case 'SET_MAIN_IMAGE':
return {
...state,
...action.payload,
};
希望能有所帮助。您需要检查的是您的操作包含哪些内容
它似乎包含了这样的东西
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: {
mainImageIndex: 2
},
}
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: 2
}
你的减速机会像
1。第一步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
2。第二步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
3。第三步
case 'SET_MAIN_IMAGE':
return {
...state,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: action.mainImageIndex,
};
case 'SET_MAIN_IMAGE':
return {
mainImageIndex: 0,
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
4。第四步
case 'SET_MAIN_IMAGE':
return {
pageNum: 1,
perPage: 4,
mainImageIndex: {
mainImageIndex: 2
},
};
你应该做什么
更改操作
有效负载以发送类似的内容
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: {
mainImageIndex: 2
},
}
{
type: 'SET_MAIN_IMAGE',
mainImageIndex: 2
}
或者更好
{
type: 'SET_MAIN_IMAGE',
payload: {
mainImageIndex: 2,
}
}
然后在减速器中使用
case 'SET_MAIN_IMAGE':
return {
...state,
...action.payload,
};
希望有帮助。因此,我能够通过为滑块创建一个新的减速器来解决问题,并将所有操作放在一个减速器中,而不是每个文件都有一个函数。然后我可以做:
导出默认组合减速机({
搜索照片,
滑块,
形式:reduxFormReducer,//安装在“形式”下
});代码>因此,我能够通过为滑块创建一个新的减速器来解决问题,并将所有操作放在一个减速器中,而不是每个文件都有一个函数。然后我可以做:
导出默认组合减速机({
搜索照片,
滑块,
形式:reduxFormReducer,//安装在“形式”下
});代码>我认为您必须使用redux immutable来解决此问题。您的嵌套对象需要是不可变的。我试图遵循这个想法,但我肯定遗漏了什么:我认为您必须使用redux immutable来解决这个问题。你的嵌套对象必须是不可变的。我试图遵循这个想法,但我肯定遗漏了一些东西:谢谢,但该操作中只有两个东西。刚刚注销:{type:“SET_MAIN_IMAGE”,mainImageIndex:2}谢谢,但该操作中只有两个内容。刚刚注销:{type:“SET_MAIN_IMAGE”,mainImageIndex:2}