我使用 immutable 创建了一个List 但是不能往里面 push 数据,redux初学者

import { combineReducers } from 'redux';

import {ADD_TO_CART,CHECKOUT_CART,INITIALIZATION} from '../actions/action.jsx';

import { List, Map , toJS } from 'immutable';


const products = List([]);


const initializateReducer = (state=products ,action) =>{


    if(!action.products){

        return state;

    }

    switch(action.type){

        case INITIALIZATION :

            for(let i=0; i< action.products.length;i++){

                state.push(Map(action.products[i]));  //push不进去????!!!

            }

            return state;

        default: 

            return state;

    }

};


红糖糍粑
浏览 844回答 1
1回答

慕田峪9158850

const initializateReducer = (state={} ,action) =>{if(!action.products){ &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;state; } switch(action.type){ &nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;INITIALIZATION&nbsp;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;{products:List(action.products)};&nbsp;&nbsp;&nbsp;&nbsp;default:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;state; }};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript