erikras / multireducer

A utility to wrap many copies of a single Redux reducer into a single key-based reducer.
MIT License
422 stars 23 forks source link

Store multireducer key in context #112

Closed me6iaton closed 8 years ago

me6iaton commented 8 years ago

One of the options - store multireducer key in react context, here is my experiment for this https://github.com/me6iaton/multireducer/commit/a15f58620580d254e6197c34a493c64055e95f67

yesmeck commented 8 years ago

What's the benefit to store reducer key in context?

me6iaton commented 8 years ago

config reducer key in root router component, once, and use connectMultireducer in deep components with the same key

yesmeck commented 8 years ago

Seems your commit is based on the version 2, connectMultireducer has been removed in version 3. If you want pass reducer key down to the child components, you can create context by yourself in version 3:

class ListComponent extends Component {
  static propTypes = {
    as: PropTypes.string.isRequired
  }

  static childContextTypes = {
    as: PropTypes.string.isRequired
  }

  getChildContext() {
    return { as: this.props.as }
  }

  render() {
    return (
      <div>
        <Item />
      </div>
    );
  }
}
yesmeck commented 8 years ago

BTW, you can find migration guide here.

me6iaton commented 8 years ago

i see, thanks