combineReducers causes code to break

前端 未结 1 548
予麋鹿
予麋鹿 2021-02-02 14:10

This is subsequent to the thread I posted here

After lot of troubleshooting I found that this code works without any problems

import React from \'react\'         


        
相关标签:
1条回答
  • 2021-02-02 14:18

    With combined reducers your store will have data structure like that:

    {
        DimensionPickerReducer: {
            dimenisionName: '',
            pickerIsLoading: false,
            pickerError: '',
            currentAttribute: '',
            attributeList: []
        },
        DataTableReducer: {
            tableData: [],
            tableIsLoading:false,
            tableError: ''
        }
    }
    

    So you should adjust your containers to work with combined store. For example in DimensionPickerContainer.js you should change mapStateToProps function:

    const mapStateToProps = (state) => {
        return {
            attributeList : state.DimensionPickerReducer.attributeList,
            currentAttribute : state.DimensionPickerReducer.currentAttribute
        }
    }
    

    You can also name your reduces in store, so they would not look ugly in data structure. E.g. combineReducers({ dimensionPicker: DimensionPickerReducer, dataTable: DataTableReducer})

    0 讨论(0)
提交回复
热议问题