title: Redux- mapStateToProps not working
body: <p>I have a react component that makes an AJAX call in componentWillMount and backs the data received in response to a redux store. Here is code</p>
  
  <pre><code>componentWillMount() {
    var self = this;
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState === 4 &amp;&amp; this.status === 200) {
        console.log(this.responseText);
        var json = JSON.parse(this.responseText);
        var data = {
          json
        };
        self.props.dispatch({
          type: "ADD_Exams",
          data
        });
      }
    };
    xmlhttp.open("GET", "http://127.0.0.1:8000/getExams/", true);
    xmlhttp.send();
  }
  </code></pre>
  
  <p>In the reducer, I am assigning the data received in action to an array defined in the reducer state.</p>
  
  <pre><code>const initialState = {
    exams:[]    
  }
  
  const examreducer = (state = initialState, action) =&gt; {
    switch (action.type) {
      case "ADD_Exams":
        return {
          ...state,
          exams: [...state.exams, action.data.json]
        };
      default:
        return state;
    }
  };
  </code></pre>
  
  <p>But when I use mapStateToProps to read exams variable I get undefined.</p>
  
  <pre><code>const mapStateToProps = (state) =&gt; {
      return {
          exams: state.exams
      }
  }
  
  export default connect(mapStateToProps)(Exam); 
  </code></pre>
  
  <p>I am creating store like this</p>
  
  <pre><code>import { Provider } from "react-redux";
  const store = createStore(loginReducer, examReducer);
  ReactDOM.render(
    &lt;Provider store={store}&gt;
      &lt;Exam /&gt;
    &lt;/Provider&gt;,
    document.getElementById("root")
  );
  
  registerServiceWorker();
  </code></pre>
  
  <p>console.log(this.props.exams) prints undefined. What is the problem here?</p>