The Class returned by high-level components cannot be rendered.

the component returned to the class wrapper using high-level components cannot be rendered correctly, but the component return can be rendered directly, and the problem can not be found. Please advise. Thank you

function HOC(WrappedComponent){
    // 
    return class HOC extends Component {
        render(){
            const newProps = {type:"HOC"};
            return <WrappedComponent {...this.props} {...newProps}/>
        }
    }
    // 
    // return function newRender(props){
    //     return <WrappedComponent />
    // }
}

class OriginComponent extends Component {
    render(){
        return <div></div>
    }
}

const newComponent = HOC(OriginComponent)

class TestHOCCom extends Component{
    constructor(){
        super()
        this.state = {
        }
    }
    render() {
        // console.log(newComponent, 9999999)
        return (
            <div>
                

<newComponent /> </div> ) } } export default TestHOCCom
Apr.02,2021

const NewComponent = HOC(OriginComponent)
<NewComponent />

be sure to use the first letter in uppercase, or jsx will compile it into a string tag.

Menu