我希望检查字符串包含大写和小写等.i具有所有false的初始状态,我想更新状态取决于值输入。我希望在更新状态的情况下返回状态结束时的状态。
const INITIAL_STATE = {lowercaseStatus:false,upperCaseEditStatus:false,allStatus:false}
export default (state = INITIAL_STATE, action) => {
switch (action.type)
{
case INPUT:
If(uppercase(action.payload.value))
{
Update upperCaseEditStatus to true
}
If(lowerCase(action.payload.value))
{
Update lowercaseStatus to true
}
If(other condition)
{
Upates props depends on corresponding condition
}
retrun state;
}
让我知道如何实现此功能?
答案 0 :(得分:1)
你可以利用...
,扩展运算符来实现这样的状态对象的不变性,
case INPUT:
temp = {};
temp.upperCaseEditStatus = uppercase(action.payload.value)
temp.lowercaseStatus = lowerCase(action.payload.value)
... //Other conditions
return { ...state, ...temp };
default:
return state;