我在redux初始状态中存储了多个值,并且我有一个动作处理程序StepOneFn,该动作处理程序正在使用组件已赋予其更改的所有值。我想更新初始状态以仅更改某些值。我不确定该怎么做。
let initial_state = {
house_name:"",
address:"",
city:"",
state:"",
zip:0,
img:"",
mortgage:0,
rent:0
}
const step_one = "step_one"
export default function reducer(state = initial_state,action){
switch(action.type){
default:
return state;
case step_one:
return {...state,...action.payload}
}
}
export function StepOneFn(name,address,city,state,zip){
return{
type:step_one,
payload:{
name,
address,
city,
state,
zip
}
}
}
答案 0 :(得分:0)
如果您只想更改某些值,可以这样做
case step_one:
return {...state, address:action.payload.address, city:action.payload.city}
}
现在,它仅根据有效负载更改城市和地址,而其他不变。