You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.
Component的两种写法:
// Function ComponentsfunctionWelcome(props){return<h1>Hello, {props.name}</h1>;}// => 等价于下面写法// Class ComponentsclassWelcomeextendsReact.Component{render(){return<h1>Hello, {this.props.name}</h1>;}}
4. Components and Props
Component的两种写法:
渲染Component的机制
官网例子:
分析component的渲染到页面上的过程:
we call
ReactDOM.render()
the<Welcome name="Sara" />
element.React calls the
Welcome
component with{name: 'Sara'}
as the props.Our
Welcome
component returns aHello, Sara
element as the resultReact DOM efficiently updates the DOM to match
Hello, Sara
.Components可以组合使用
Components
可以组合使用,也可以将常用部分提取出来作为components
The text was updated successfully, but these errors were encountered: