反应redux组件不更新

时间:2017-01-20 18:48:22

标签: reactjs redux react-redux

我有一个“容器”组件,其中包含mapStateToProps和mapDispatchToProps以及connect。

在视图组件中,我显示了props数据,并有一个调用容器方法的方法。

我的问题是,在我更新状态后(我看到它在devtools上更新),视图容器没有更新。

我想也许是因为道具对象很复杂......

<*> ****找到了源头,无法真正理解为什么会有人在这里,希望如此。

当我在“mapStateToProps”中使用“全局”变量时,出现了这个问题,当我简单地将内容粘贴到内部而非静态变量时,一切运行良好。

代码:

//this is what was the problem HERE
let staticVariable = [ ... ];

const mapStateToProps = (state, props) => {

    let review = state.reviews.reviews.reviews[props.params.id];

    return {
        review,
        items: staticVariable
    };
};

const mapDispatchToProps = (dispatch, props) => {
    return {
        whatever: dispatch(updateState())
    };
};

let OverviewContainer = connect(mapStateToProps, mapDispatchToProps)(Overview);
export default OverviewContainer;

只是为了查看这是状态:

{
    something: {},
    something2: {},
    something3: {},
    reviews: {
        dontcare: 1,
        reviews: {
            reviews: {
                1: {
                    dontcare: 1,
                    assets: [
                        {

                        }
                    ]   
                }             
            }
        },
    },
}

0 个答案:

没有答案
相关问题