React总结三(组件&Props)

 

组件允许你将 UI 拆分为  独立可复用的 代码片段,并对每个片段进行独立构思.

 

a. 组件是什么

组件,从概念上类似于 JavaScript 函数。

它接受任意的入参(即 “props”),并返回用于描述页面展示内容的 React 元素。

 

b.定义组件(函数组件 & class组件)

//函数组件

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

 

//class组件

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

c. 渲染组件

未完待续... 

posted @ 2021-04-12 14:23  CatherLee  阅读(42)  评论(0编辑  收藏  举报