Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React中扩展React.component的类是什么_Reactjs_Higher Order Functions_Es6 Class - Fatal编程技术网

Reactjs React中扩展React.component的类是什么

Reactjs React中扩展React.component的类是什么,reactjs,higher-order-functions,es6-class,Reactjs,Higher Order Functions,Es6 Class,在此链接中 其中解释为高阶组件。下面的代码具有类扩展React.component。这里的class关键字是什么 function logProps(WrappedComponent) { return class extends React.Component { componentDidUpdate(prevProps) { console.log('Current props: ', this.props); console.log('Previous

在此链接中 其中解释为高阶组件。下面的代码具有类扩展React.component。这里的class关键字是什么

function logProps(WrappedComponent) {
  return class extends React.Component {
    componentDidUpdate(prevProps) {
      console.log('Current props: ', this.props);
      console.log('Previous props: ', prevProps);
    }
    render() {
      // Wraps the input component in a container, without mutating it. Good!
      return <WrappedComponent {...this.props} />;
    }
  }
}
函数日志道具(WrappedComponent){
返回类扩展了React.Component{
componentDidUpdate(prevProps){
log('Current props:',this.props);
log('previousprops:',previprops);
}
render(){
//将输入组件包装在容器中,而不会对其进行变异。很好!
返回;
}
}
}

这是一个未命名的

上面的代码通过扩展
React.Component
类来创建一个未命名/匿名类,因此,创建一个新的React组件,该组件包装(返回)传递给函数
logProps
WrappedComponent

类表达式的语法为:

const MyClass=class[className][扩展其他className]{
//阶级团体
};
其中名称
className
(并且,
扩展了其他className
)是可选的

而且,在您所讨论的代码中,它只是返回结果,而不是将其分配给变量:

return class [className] [extends otherClassName] {
    // class body
};
请注意,有两种方法可以创建一个,一种是通过编写
函数
,另一种是通过编写


而且,在JavaScript中,是在ECMAScript 2015(也称为ES6)中引入的。

您可以使用类创建组件,
下面是一个用于构建
return class [className] [extends otherClassName] {
    // class body
};