I am working through react. Used the connect decorator in my main component than passed the store down with props. As my playground app is growing this approach feels stupid. But then again is repeating the same decorator the way to go.
@connect((store)=>{
return{
users: store.users,
tweets: store.tweets
}
})
// Routing
class Routing extends React.Component{
render(){
var children = this.props.users;
const routes = {
path: '/',
storeContent: this.props,
component: Nav,
indexRoute: { component: Layout },
childRoutes: [ ]
}
for (var i = children.length - 1; i >= 0; i--) {
routes.childRoutes.push({path: children[i], component: Layout})
};
return(<Router className="row" routes={routes} history={browserHistory} />)
}
}
ReactDOM.render( <Provider store={store}><Routing /></Provider>, document.querySelector('#main'));
The above routing calls on my Nav
and Layout
component. Instead of using the same @connect
decorator for those components, I do this
this.props.routes[0].storeContent.users
It looked impresive when I learned it but now it feels that it be easier if I do this
@connect((store)=>{
return{
users: store.users,
tweets: store.tweets
}
})
export default class Nav extends React.Component{
.....
}
@connect((store)=>{
return{
users: store.users,
tweets: store.tweets
}
})
export default class Layout extends React.Component {
...
}