reactjs - It's necessary to connect every React Component with redux even when using Provider? -
my app index start with:
reactdom.render( <provider store={store}> <router history={browserhistory}> <route path="/" component={app}> <indexroute component={main} /> <route path="/search" component={moviesearch} /> <route path="/movies" component={movielist} /> </route> </router> </provider>, document.getelementbyid('root') );
my main.js: render() { return (<div>{this.props.children}</div> )}
when access uri: /movies movielist props stay undefined until connect component store. correct? need connect every component store access state? can't props main parent props without this?
i need call mapstatetoprops , mapdispatchtoprops access state , actions ?
this default/good practice?
the answer is, yes
unless have layout
component, need connect each component work redux
.
you can take @ one of project. used page.js router. simple , solves purpose. every route, pass name of component rendered. so, layout
page loaded connect redux , pass state props
child components. , based on render
passed router
. render component inside layout
.
using layout
practice. becomes common place components gets rendered.
useful links:
[update]
you should take @ redux router
Comments
Post a Comment