state 和 props 主要的区别在于 props 是不可变的,而 state 可以根据与用户交互来改变。

React Props 语法

state 和 props 主要的区别在于 props 是不可变的,而 state 可以根据与用户交互来改变。

React Props 示例

var HelloMessage = React.createClass({
  render: function() {
    return <h1>Hello {this.props.name}</h1>;  }}); 
ReactDOM.render(
  <HelloMessage name="php.cn" />,  document.getElementById('example')


热门推荐