enthusiasm.tsxconst mapStateToProps = (state: IReducers) => ({ enthusiasm: state.enthusiasm });
const withConnect = connect(
mapStateToProps
);
const persistEnthusiasmConfig = {
key: 'enthusiasm',
storage,
version: 10
};
const reducer = {
enthusiasm: persistReducer(persistEnthusiasmConfig, enthusiasm)
};
const withReducer = injectReducer<IReducers>(reducer);
export default compose(
withReducer,
withConnect
)(Enthusiasm);
injectReducer.tsimport React, { Component } from 'react';
import { ReducersMapObject } from 'redux';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { injectReducer } from '@store';
/**
* Dynamically injects a reducer
*
* @param {function} reducer A reducer that will be injected
*
*/
export default function <S>(reducer: Partial<ReducersMapObject<S>>) {
return (WrappedComponent: any) => {
class ReducerInjector extends Component {
static WrappedComponent = WrappedComponent;
constructor(props: object) {
super(props);
injectReducer(reducer);
}
render() {
return <WrappedComponent {...this.props}/>;
}
}
return hoistNonReactStatics(ReducerInjector, WrappedComponent);
};
}
store.tsexport function injectReducer(reducer: Partial<ReducersMapObject<IReducers>>) {
if (store.injectedReducers) {
if (Reflect.has(store.injectedReducers, Object.keys(reducer)[0])) {
return;
}
Object.assign(store.injectedReducers, reducer);
store.replaceReducer(createReducer(store.injectedReducers));
}
}
This code executes normally in the development environment, but redux-persist does not execute properly after the build
@a1992012015 how did you solve this?
thumb downed the issue for closing it without sharing a solution
Most helpful comment
@a1992012015 how did you solve this?