如何访问商店以动态加载减速器

时间:2019-04-17 11:17:39

标签: reactjs typescript redux react-redux

我正在尝试从下面的链接中实现使用Typescript动态加载reducer的方法。有人可以建议一种访问商店的方法,并调用商店的自定义方法来注入reducer。

https://tylergaw.com/articles/dynamic-redux-reducers/

这是withReducer的转换

const withReducer = (key:any, reducer:any) => (WrappedComponent:any) => {
   const Extended: React.FunctionComponent<any> = (props, context) => {
      context.store.injectReducer(key, reducer)
      return <WrappedComponent {...props} />
   };

   Extended.contextTypes = {
      store: object
   };

    return Extended;
};

export { withReducer };

我如何在这里访问商店。 context.store是未定义的。

1 个答案:

答案 0 :(得分:0)

看起来上述方法不再是react-redux v6.0.0的支持者。这是another approach