简体   繁体   English

Redux Store未连接到React组件

[英]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.

相关问题 连接到Redux存储的React组件的递归呈现 - Recursive rendering of React component connected to Redux store 在React / Redux中测试连接的组件 - Test connected component in React/Redux React Redux,我的组件未连接到Redux Store。 我在另一个组件中测试了动作和减速器,它是否对其他组件有效? - React Redux, my component is not connected to Redux Store. I tested the action and reducer in another component, it does work for other components? React-Redux 和材料 UI:组件未将存储传递给“已连接”子级 - React-Redux & Material UI: Component doesn't pass store to 'connected' child 使用某些道具(React / Redux)进行连接组件测试 - Connected Component testing with certain prop (React/Redux) React Redux:连接的子组件未接收道具 - React Redux: Connected child component not receiving props React Redux 使用 HOC 和连接组件 - React Redux use HOC with connected component 如何在Enzyme / React中测试包含连接到Redux的组件的组件? - How to test component that contains a component connected to Redux in Enzyme / React? react 组件已连接,redux 状态发生变化……但组件没有更新? - react component connected, redux state changes… but no update to component? 组件连接到商店但反应没有重新查看视图 - Component connected to the store but react not rerendering view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM