React-High-level components are simple to use

import React from 'react';

function Child(props){
    return <div>Child</div>
}

const foo = Cmp => props => {
    return <Cmp {...props}/>
}

const foo = Cmp => {
    return props => {
        return <Cmp {...props}/>
    }
}

export default function HocPage(props) {
    const Foo = foo(Child);
    return (
        <div>
            HocPage
            <Foo/>
        </div>
    )
}

Note: how to write the decorator:

1. Decorators can only be used on class components

2. The execution order is from bottom to top

Example:

@withLog

@withContent

Published 35 original articles · won praise 1 · views 6718

Guess you like

Origin blog.csdn.net/qq_36162529/article/details/102670687