Reactjs 如何使用react和redux saga将新对象添加到现有状态

Reactjs 如何使用react和redux saga将新对象添加到现有状态,reactjs,react-redux,redux-saga,reducers,Reactjs,React Redux,Redux Saga,Reducers,我有一个物体,上面有这样的信息 导出常量初始设置={ id:'01', 名称:“”, 拉丁语:'', 长:“, 地址行1:“”, 地址行2:“”, 城市:'', 声明:'', 国家:“, zipcode:“”, 状态:“”, lastCommunicateDateTime:“”, { PatientID:'1', 名字:“Manav”, 姓氏:“潘迪亚”, 出生日期:'', 美孚利诺:“, 订单:[ { orderId:'01', 拾取代码:“XYZ456”, 总数:40.0, 税率:3, 保

我有一个物体,上面有这样的信息

导出常量初始设置={
id:'01',
名称:“”,
拉丁语:'',
长:“,
地址行1:“”,
地址行2:“”,
城市:'',
声明:'',
国家:“,
zipcode:“”,
状态:“”,
lastCommunicateDateTime:“”,
{
PatientID:'1',
名字:“Manav”,
姓氏:“潘迪亚”,
出生日期:'',
美孚利诺:“,
订单:[
{
orderId:'01',
拾取代码:“XYZ456”,
总数:40.0,
税率:3,
保险金额:20.0,
totalCoPayAmount:40.0,
总Paidamount:40.0,
总额:'',
付款到期日:“”,
项目:[
{
itemId:'01',
图像:'https://via.placeholder.com/30',
}
]
}
]
},
{
PatientID:'2',
名字:“Manav”,
姓氏:“潘迪亚”,
出生日期:'',
美孚利诺:“,
订单:[
{
orderId:'01',
拾取代码:“XYZ456”,
总数:40.0,
税率:3,
保险金额:20.0,
totalCoPayAmount:40.0,
总Paidamount:40.0,
总额:'',
付款到期日:“”,
项目:[
{
itemId:'01',
图像:'https://via.placeholder.com/30',
}
]
}
]
}
]

};在reducer中应该是这样的:

case 'add':
    return {
        ...state, // old object should remains same
        patients: [state.patients, action.payload] // new item
    };

你应该加减速器

case 'add':
  return {
    ...state,
    error: false,
    loading: false,
    data: state.data.concat(action.data), }
之后,您需要选择器将数据从选择器发送到州

export const getDataDetail = state => getDataDetail(state)?.data;
最后一个选项是您应该调用更新的数据。你应该使用

componentWillRecieve(nextProps) {
  ...... use your data match with nextProps and props
 if(nextData && nextData !== this.props.yourData) {
     this.setState({ data : nextData }) }}

应该是这样的。

这对我来说不是正确的解决方案,我正在使用immutablejs的Map(),我不需要调用componentWillReceive(),我只需要专门针对reducer的解决方案,谢谢您需要在reducer中分发患者列表:
患者:[……state.patients,action.payload]