Search code examples
javascriptreactjsreduxredux-form

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? 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.

Thanks!


Solution

  •  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}). Updated your plunker sample so it looks like it works now.