如何将HOC与compose(redux)结合使用?

时间:2020-03-18 08:53:36

标签: javascript reactjs typescript redux higher-order-components

我有一个来自@ material-ui / core的命名为ThemeProvider的HOC,我想将其与compose一起使用。现在我有了这个组件:

import {hot} from 'react-hot-loader/root';

    interface IRoutesProps {
    isTokenVerifying: boolean;
    userPalette: IPalette;
}

const Routes = ({isTokenVerifying, userPalette}: IRoutesProps) => {
    if (isTokenVerifying) {
        return (
            <LoadIndicator
                id='large-indicator'
                height={50}
                width={50}
                elementAttr={{class: styles.loader}}
            />
        );
    }

    return (
        <ThemeProvider theme={defaultMaterialTheme(userPalette)}>
            <Switch>
                 ....
            </Switch>
        </ThemeProvider>
    );
};

const mapStateToProps = (state: RootState) => ({
    isTokenVerifying: getPendingTokenVerify(state),
    userPalette: getUserPalette(state),
});

export default hot(connect(mapStateToProps)(Routes));

如何通过compose做到这一点?我尝试过这种情况,但是没有用:

const ThemeProviderContainer = ({ children, userPalette }: any) =>
    <ThemeProvider theme={defaultMaterialTheme(userPalette)}>
        {children}
    </ThemeProvider>;

export default hot(
    compose(connect(mapStateToProps), ThemeProviderContainer),
)(Routes);

0 个答案:

没有答案