How to use Immutable.js with redux?

后端 未结 5 844
-上瘾入骨i
-上瘾入骨i 2020-12-07 09:53

Redux framework is using reducers to change app state in response to an action.

The key requirement is that a reducer cannot modify an existing state object; it must

5条回答
  •  情深已故
    2020-12-07 10:09

    Taking your good example with Immutable

    import {
        ACTIVATE_LOCATION
    } from './actions';
    
    import { Map } from 'immutable';
    
    const initialState = Map({})
    
    export let ui = (state = initialState, action) => {
      switch (action.type) {
        case ACTIVATE_LOCATION:
          return state.set('activeLocationId', action.id);
        default:
          return state;
      }
    };
    

提交回复
热议问题