react-redux-starter-kit icon indicating copy to clipboard operation
react-redux-starter-kit copied to clipboard

How to Inject the reducer in Only Smart Component Only without Using routes

Open tariqulislam opened this issue 8 years ago • 1 comments

tariqulislam avatar Jan 12 '17 15:01 tariqulislam

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! :)

Tailzip avatar Feb 05 '17 19:02 Tailzip