• home > webfront > ECMAS > react >

    react中redux里面的reducer splice 不能用问题!~

    Author:[email protected] Date:

    react中redux里面的reducer splice 返回不生效。

    react中redux里面的reducer splice  返回不生效。必须,slice()副本,再修改!

    let tem=state.listArr;
          tem.splice(action.index,1);

    千说万说,不如代码有效:

    比如:

    const reducer=(state=states,action)=>{
      switch (action.type){
        case 'add':
          console.log(state.listArr);
          return{
            ...state,
            listArr:state.listArr.concat([state.value])
          };
        case 'del':
          let tem=state.listArr.slice();
          tem.splice(action.index,1);
          return{
            ...state,
            // listArr:[].concat(state.listArr.slice(0,action.index),state.listArr.slice(action.index,state.listArr.length))
            listArr:tem
          };
        case 'change':
    
          return{
            ...state,
            value:action.obj.target.value
          };
        default:
          return state;
    
      }
    };



    转载本站文章《react中redux里面的reducer splice 不能用问题!~》,
    请注明出处:https://www.zhoulujun.cn/html/webfront/ECMAScript/jsBase/2017_0315_7963.html