javascript - Root route component not connecting to redux -
i'm stuck on problem seems obvious: root component of router not being subscribed store changes , it's not receiving props though mapstatetoprops called.
my routes defined plain objects:
const createroutes = (store) => { path: '/', component: rootcomponent, indexroute: home, childroutes: [ subroute ] } export default createroutes
then import object when creating app:
let render = () => { const routes = require('./routes').default(store); reactdom.render( <appcontainer store={store} routes={routes} />, mount_node ) }
my rootcomponent looks this:
const rootcomponent = ({address, action}) => { <div> {console.log('addr: ' + address)} <button onclick={action}>test</button> </div> } const mapstatetoprops = (state) => { console.log('mapstatetoprops'); return {address: state.address}; } const mapdispatchtoprops = (dispatch) => { action = (evt) => { console.log('mapdispatchtoprops'); dispatch({type: 'test', payload: {address: 'xxx'}}); } } export default connect(mapstatetoprops, mapdispatchtoprops)(rootcomponent)
when click button, dispatch works since can see in devtools state changed. mapstatetoprops , mapdispatchtoprops invoked rootcomponent never updated.
if same code child routes, works fine! ideas on why rootcomponent not being subscribed store?
edit: way, <appcontainer />
using <provider />
react-redux
. code this:
class appcontainer extends component { render () { const { routes, store } = this.props return ( <provider store={store}> <router history={browserhistory} routes={routes} /> </provider> ) } }
you make no mention of using <provider />
component react-redux, i'm guessing must defining somewhere in case you're not:
it <provider />
makes store available connect call make in container component.
Comments
Post a Comment