@connect(
state=>state.authority,
{logout}
)
function Er(){
return <h2>这是Er</h2>
}
function Three(){
return <h2>这是Three</h2>
}
Failed to compile
./src/dashbord.js
Syntax error: e:\项目文件夹\react练习\reacthello\hello\my-app\src\dashbord.js: Leading decorators must be attached to a class declaration (15:0)
13 | )
14 |
> 15 | function Er(){
| ^
16 | return <h2>这是Er</h2>
17 | }
18 |
This error occurred during the build time and cannot be dismissed,此时页面报错无法渲染组件
当将
function Er(){
return <h2>这是Er</h2>
}
function Three(){
return <h2>这是Three</h2>
}
@connect(
state=>state.authority,
{logout}
)
修饰器放在后面时页面不再报错。
装饰器的作用:
当使用装饰器后将状态引入到此组件中。