react-redux-starter-kit
react-redux-starter-kit copied to clipboard
How to Inject the reducer in Only Smart Component Only without Using routes
I'm not sure if it's the right way to do it, but here's the solution I've come up with.
I'm injecting the reducer in my smart component's constructor method like this:
import React, { Component, PropTypes } from 'react';
import reducer from 'path-to-reducer';
import { injectReducer } from 'path-to-inject-reducer';
export default class SmartComponent extends Component {
static contextTypes = {
store: PropTypes.object
};
constructor (props, context) {
super(props);
// function provided by the starter kit
injectReducer(context.store, { key: 'key', reducer });
}
render () {
// ...
}
}
Hope this helps! :)