[英]Redux Store not connected to React Component
I have this plunkr here : 我在这里有这个笨蛋:
ReactDOM.render(
<ReactRedux.Provider store={store}>
<div>
<MyComponent/>
<button onClick={loadInitialValues} className="btn btn-default">
LOAD VALUES
</button>
</div>
</ReactRedux.Provider>,
document.getElementById('root')
);
Why my React Component (MyComponent) is not updated when the button " LOAD VALUES " is clicked? 为什么单击“ LOAD VALUES ”按钮时我的React Component(MyComponent)没有更新? It seems that everything is fine. 看来一切都很好。 The action is dispatched, then in my reducer I look for the action " LOAD_VALUES
" and I return the new values, but the React Component doesn't get updated and stays the same. 分派了动作,然后在我的化简器中寻找动作“ LOAD_VALUES
”,然后返回新值,但是React Component不会得到更新并且保持不变。
Thanks! 谢谢!
var suaReducer = function(state = Immutable.Map({
modalProps: Immutable.Map({
editMode: false,
paymentType: Immutable.Map({})
})
}), action) {
switch(action.type) {
case LOAD_VALUES:
return state.merge({
modalProps: Immutable.Map({
editMode: true,
paymentType: Immutable.Map({
name: "TEST",
notes: "TEST",
amounts: [{
amount: 100,
year: 2017
}]
})
})
});
}
return state;
}
Just changed you switch
statement instead of action
use action.type
since action
is an object you are dispatching ( {type: LOAD_VALUES}
). 只是更改了switch
语句,而不使用action
使用action.type
因为action
是您要调度的对象( {type: LOAD_VALUES}
)。 Updated your plunker sample so it looks like it works now. 更新了插件示例,使其看起来像现在一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.