使用状态挂钩将类组件重写为功能组件时,如何编写this.props
?
例如:
class BasicLayout extends PureComponent {
render() {
//...
const { children, location, loading } = this.props;
//...
}
}
答案 0 :(得分:2)
使用功能组件时,道具可以作为带有或不带有钩子的函数参数使用。上面的类组件可以简单地写为
select te.name as leaderName,te1.name as childName from tbl_employee as te join tbl_employee as te1 on te.id = te1.leaders
挂钩不会影响您使用道具的方式,但会使用const BasicLayout = (props) => {
//...
const { children, location, loading } = props;
// ...
}
挂钩提供API以在功能组件中使用state, context, lifecycle implementation