reactjs - mapStateToProps must return an object. Instead received undefined -


i'am using react redux on frontend , calling elixir phoenix backend api. seems work have error in javascript console

error: mapstatetoprops must return object. instead received undefined.

i have implemented redux logger , objects seen him reduxlog

i can not see incorrect there, after action objects correct. can see in phoenix user has both joined socket , channel.

since error seems around mapstatetoprops had better @ code

import react 'react';  import {    connect  }  'react-redux';    class authenticatedcontainer extends react.component {    componentdidmount() {      const {dispatch} = this.props;    }      render() {      const {currentuser, dispatch, socket} = this.props;      if (!currentuser) return false;      return ( < div id = "authentication_container"        classname = "application-container" >        < div classname = "main-container" > {          this.props.children        } < /div>              </div >      );    }  }    const mapstatetoprops = (state) => ({    currentuser: state.session.currentuser,    socket: state.session.socket,    channel: state.session.channel,  });  export  default connect(mapstatetoprops)(authenticatedcontainer);

here session reducer

import constants '../constants';    const initialstate = {      currentuser: null,      socket: null,      channel: null,      error: null,  };    export default function reducer(state = initialstate, action = {}) {      console.log(action)      switch(action.type) {          case constants.current_user:              return { ...state, currentuser: action.currentuser, socket: action.socket, channel: action.channel};            case constants.user_signed_out:              return initialstate;            case constants.sessions_error:              return { ...state, error: action.error };            default:              return state;      }  }

and combined reducer

import { combinereducers }  'redux';  import { routerreducer }     'react-router-redux';  import session              './session';  import registration         './registration';    export default combinereducers({      routing: routerreducer,      session: session,      registration: registration,  });

when go through code , try debug can not find instance when state undefined props. i'am using lot of code https://github.com/bigardone/phoenix-trello.

all appreciated.

best regards björn

i found out causing problem me. once redux call finished code went on , redirected me controller. controller had view , mapstatetoprops had undefined value. fixed , error went away.

but limited redux knowledge looking @ wrong things since see logger failing in action "current_user". when failing in action "fetch_milestone" witch mapping undefined value props. reading on subject, if reads , has understanding of happening appreciated.

possible fix others seeing problem, check calls mapstatetoprops , see if value undefined.


Comments