无状态 : function
有状态 : class
1.具有生命周期,
<script type="text/babel">
class Hello extends React .Component {
//无状态直接用return,有状态需要用render()进行渲染
render(){
return <h1>Hello World</h1>
}
}
ReactDOM.render(
<Hello />,
document .getElementById( 'root' )
</script>
结语:
更多的社会我们应该使用无状态的组件,因为有状态组件会自动触发生命周期,一旦触发它生命周期的函数,它就会影响当前项目的运行,所以尽可能得使用无状态组件。