在 ES6 语法中,很容易理解从 React 扩展 Component 的组件是 React 组件。例如:
import { Component } from 'react';
class ExampleComponent extends Component {
render(){
return(
//render component content here
)
}
}
但是如果您使用无状态组件方法重写它:
const ExampleComponent = (props) => {
return
//render component content here
}
...幕后发生了什么,使该组件继承了 Component 的生命周期行为?
最佳答案
作为函数的无状态组件,充当生命周期方法中的渲染方法的主体。当您将组件定义为函数时,它被包装在类的渲染方法中。
组件类的 render() === 无状态组件函数
关于javascript - react : what determines that a Stateless React component is actually a React component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42982739/