求帮助。
现在是想做异步加载模块,动态添加reducer,需要获取到根store
store.ts
import { createStore, combineReducers } from 'redux';
export function CreateStore(reducerMap: any)?{
console.log('reducerMap2',reducerMap);
//?@ts-ignore
const injectAsyncReducers =?(store, name, reducers) => {
let asyncReducers;
if (typeof reducers === "function")?{
asyncReducers = reducers;
}
if (typeof reducers === "object")?{
asyncReducers = combineReducers(reducers);
}
store.asyncReducers[name]?= asyncReducers;
store.replaceReducer(
combineReducers({
...reducerMap,
...store.asyncReducers
})
);
};
const store = createStore(
combineReducers(reducerMap),
//?@ts-ignore
//???applyMiddleware(logger)
);
//?@ts-ignore
store.asyncReducers =?{};
//?@ts-ignore
store.addDynamicModule =?({ name, reducers }) => {
console.info(`Registering?module?reducers?for ${name}`);
injectAsyncReducers(store, name, reducers);
};
//?@ts-ignore
store.removeDynamicModule = name => {
console.info(`Unregistering?module?reducers?for ${name}`);
const noopReducer =?(state =?{}) => state;
injectAsyncReducers(store, name, noopReducer);
};
return store;
}
但是我在lazyModule中无法获取到store
static contextTypes =?{
//?count:?PropTypes.object,
store: PropTypes.object
}
也添加了
<Provider store={CreateStore(CounterReduce)}>
求帮助分析一下,怎么才能获取到store呢?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…