Take state for react high-level components

High-level components A

import React from "react"

const A = WrappedComponent =>{
    class HOC extends React.Component {
        constructor(props){
            super(props);
            this.WCRef = React.createRef();
        }
        
        componentDidMount(){
            // state
            console.log(this.WCRef.current.state)
        }
        
        render(){
            return {
                <div>
                    A
                    <WrappedComponent ref={this.WCRef} />
                </div>
            }
        }
    }
    return HOC
}

export default A

Common component B

import React from "react"
import A from "./A" //A

class MyComponent extends React.Component {
    state = {
        test: "Bstate"
    }
    
    render(){
        return (
            <div>
            B
            </div>
        )
    }
}

export default A(MyComponent)

the above components work normally, but after MyComponent uses withStyles of Material-UI , A component cannot get state of MyComponent .

import React from "react"
import A from "./A" //A
import PropTypes from "prop-types"
import withStyles from "@material-ui/core/styles/withStyles"

const styles = theme =>({
    root:{
        backgroundColor: theme.palette.primary.main
    }
});

class MyComponent extends React.Component {
    state = {
        test: "Bstate"
    }
    
    render(){
        const {classes} = this.props;
        return (
            <div className={classes.root}>
            B
            </div>
        )
    }
}

MyComponent.propTypes = {
    classes:PropTypes.object.isRequired
};

export default A(withStyles(styles)(MyComponent))

simply changes A (MyComponent) to A (withStyles (styles) (MyComponent)) . Is there a way to keep withStyles and use A to get state of MyComponent ?

May.09,2022

found a solution
higher-order components A

render(){
    const {classes,...otherProps} = this.props;
    
    ...
    // 
    <WrappedComponent {...otherProps}/>
}

Common components

import {compose} from "redux";

...

export default compose(
    A,
    withStyles(styles),//
)(MyComponent)

/* 

export default A(withStyles(styles)(MyComponent))

*/
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35507-4050f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35507-4050f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?