state 和 props 主要的區(qū)別在于 props 是不可變的,而 state 可以根據(jù)與用戶交互來改變。

React Props 語法

state 和 props 主要的區(qū)別在于 props 是不可變的,而 state 可以根據(jù)與用戶交互來改變。

React Props 示例

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


熱門推薦