React-高阶组件简单使用

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>
    )
}

注意:装饰器写法:

1、装饰器只能用在class组件上

2、执行顺序从下往上

例:

@withLog

@withContent

发布了35 篇原创文章 · 获赞 1 · 访问量 6718

猜你喜欢

转载自blog.csdn.net/qq_36162529/article/details/102670687