javascript - React-Redux container throws "mapStateToProps() in Connect(ModalRoot) must return a plain object. Instead received undefined." -
i building redux based model/dialog trigger based on dan abramov's solution question: dan abramov's solution
the error getting "mapstatetoprops() in connect(modalroot) must return plain object. instead received undefined."
here code modal container , code calls it:
// code calls modal container import react 'react'; import { provider } 'react-redux'; import { connector horizonconnector } 'horizon-react'; import getmuitheme 'material-ui/styles/getmuitheme'; import muithemeprovider 'material-ui/styles/muithemeprovider'; import routes '../routes'; import store '../store'; import horizon '../db'; import modalroot './modal'; export default () => ( <muithemeprovider muitheme={getmuitheme()}> <horizonconnector horizon={horizon} store={store}> <div classname="app"> {routes} <modalroot /> </div> </horizonconnector> </muithemeprovider> );
// modal container import loginmodal '../components/modals/loginmodal' import {connect} 'react-redux' const modal_components = { 'login_modal': loginmodal /* other modals */ } const modalroot = ({ modaltype, modalprops }) => { if (!modaltype) { return <span /> // after react v15 can return null here } const specificmodal = modal_components[modaltype] return <specificmodal {...modalprops} /> } export default connect( state => state.modal )(modalroot)
simple i'm forgetting driving me crazy, comments or suggestions welcome.
according redux implementation , example should write this
export default connect( state => ({ modal: state.modal }) )(modalroot)
see here