Skip to content

MapStateToProps not being called even after changing STATE in reducer. #1875

@shivateja-madipalli

Description

@shivateja-madipalli

Do you want to request a feature or report a bug?

I am retrieving data from Salesforce using JS remote Actions and populating data in React JS.

The structure of my application:

My component1.js:

import React from 'react';
const component1 = React.createClass({

  getInitialState() {
    return {
      basicData : {},
      interestData : {},
      accountingData : {},
      isLoading : true
    }
  },

  componentWillMount() {
    console.log('componentWillMount');
  },

  componentDidMount() {
    console.log('componentDidMount');
    this.props.action1();
  },

  componentWillReceiveProps(NextProps) {
    console.log('componentWillReceiveProps', NextProps);
  },

  componentWillUnmount() {
    console.log('componentWillUnmount');
  },

  render()  {
    console.log('RENDERING');
    return (
      <div>
        <p> Loading! </p>
      </div>
    )

  }

});

export default component1;

This is my container.js

import React, { Component } from 'react';
import { connect } from 'react-redux';
import RootComponent from '../components/component1.js';
import { action1 } from '../actions/actionCreators';

function mapStateToProps(globalState) {
  return {
    value1: globalState.value1,
    value2: globalState.value2
  };
}

const mapDispatchToProps = (dispatch) => {
  return {
     getData: () => {
        dispatch(getData())
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(component1);

Action creator:

export function action1() {
  return {
    type: 'RETRIEVE_REQUESTED_DATA',
    value1: getRecords()
  };
}

Reducer:

        case "RETRIEVE_REQUESTED_DATA":
          action.value1.then(function(data) {
            return testVar = { ...state, basicData: state.basicData, interestData: data, accountingData: state.basicData, isLoading: false};
          });

Though, I am returning altered state from my reducer, MapStateToProps in my container is not being invoked.

The server call returns a promise and that promise is handled in reducer here, once the data is retrieved then I am populating the data to my state.

My view to the issue,

Once data is retrieved from DB (Salesforce), state is altered thus, MapStateToProps should be invoked because it is connected to the Component with Connect.

Please shed some light.

I am very new to Redux and React not sure whether this is a issue or a usage question, pls excuse my ignorance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions