跳到主要内容

Props 数据流

props 是 React 组件的输入。它们是从父组件向下传递给子组件的数据。props 是只读的,无论是使用函数声明还是通过 class 声明。 函数组件与 class 组件

函数组件与 class 组件

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

props.children

每个组件都可以获取到 props.children。它包含组件的开始标签和结束标签之间的内容。

function Welcome(props) {
return <p>{props.children}</p>;
}

<Welcome>Hello world!</Welcome>;