\u66f4\u65b0\u5143\u7d20\u6e32\u67d3<\/strong><\/div>\nReact \u5143\u7d20\u90fd\u662f\u4e0d\u53ef\u53d8\u7684\u3002\u5f53\u5143\u7d20\u88ab\u521b\u5efa\u4e4b\u540e\uff0c\u4f60\u662f\u65e0\u6cd5\u6539\u53d8\u5176\u5185\u5bb9\u6216\u5c5e\u6027\u7684\u3002<\/p>\n
\u76ee\u524d\u66f4\u65b0\u754c\u9762\u7684\u552f\u4e00\u529e\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\uff0c\u7136\u540e\u5c06\u5b83\u4f20\u5165 ReactDOM.render() \u65b9\u6cd5\uff1a<\/p>\n
\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a\u8ba1\u65f6\u5668\u7684\u4f8b\u5b50:<\/p>\n
\u5b9e\u4f8b<\/p>\n
\r\nfunction tick() {\r\n const element = (\r\n <div>\r\n <h1>Hello, world!<\/h1>\r\n <h2>\u73b0\u5728\u662f {new Date().toLocaleTimeString()}.<\/h2>\r\n <\/div>\r\n );\r\n ReactDOM.render(\r\n element,\r\n document.getElementById('example')\r\n );\r\n}\r\n \r\nsetInterval(tick, 1000);<\/pre>\n\u4ee5\u4e0a\u5b9e\u4f8b\u901a\u8fc7 setInterval() \u65b9\u6cd5\uff0c\u6bcf\u79d2\u949f\u8c03\u7528\u4e00\u6b21 ReactDOM.render()\u3002<\/p>\n
\u6211\u4eec\u53ef\u4ee5\u5c06\u8981\u5c55\u793a\u7684\u90e8\u5206\u5c01\u88c5\u8d77\u6765\uff0c\u4ee5\u4e0b\u5b9e\u4f8b\u7528\u4e00\u4e2a\u51fd\u6570\u6765\u8868\u793a\uff1a<\/p>\n
\u5b9e\u4f8b<\/p>\n
\r\nfunction Clock(props) {\r\n return (\r\n <div>\r\n <h1>Hello, world!<\/h1>\r\n <h2>\u73b0\u5728\u662f {props.date.toLocaleTimeString()}.<\/h2>\r\n <\/div>\r\n );\r\n}\r\n \r\nfunction tick() {\r\n ReactDOM.render(\r\n <Clock date={new Date()} \/>,\r\n document.getElementById('example')\r\n );\r\n}\r\n \r\nsetInterval(tick, 1000);\r\n<\/pre>\n\u9664\u4e86\u51fd\u6570\u5916\u6211\u4eec\u8fd8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a React.Component \u7684 ES6 \u7c7b\uff0c\u8be5\u7c7b\u5c01\u88c5\u4e86\u8981\u5c55\u793a\u7684\u5143\u7d20\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u5728 render() \u65b9\u6cd5\u4e2d\uff0c\u9700\u8981\u4f7f\u7528 this.props \u66ff\u6362 props\uff1a<\/p>\n
\u5b9e\u4f8b<\/p>\n
\r\nclass Clock extends React.Component {\r\n render() {\r\n return (\r\n <div>\r\n <h1>Hello, world!<\/h1>\r\n <h2>\u73b0\u5728\u662f {this.props.date.toLocaleTimeString()}.<\/h2>\r\n <\/div>\r\n );\r\n }\r\n}\r\n \r\nfunction tick() {\r\n ReactDOM.render(\r\n <Clock date={new Date()} \/>,\r\n document.getElementById('example')\r\n );\r\n}\r\n \r\nsetInterval(tick, 1000);<\/pre>\n","protected":false},"excerpt":{"rendered":"\u5143\u7d20\u662f\u6784\u6210 React \u5e94\u7528\u7684\u6700\u5c0f\u5355\u4f4d\uff0c\u5b83\u7528\u4e8e\u63cf\u8ff0\u5c4f\u5e55\u4e0a\u8f93\u51fa\u7684\u5185\u5bb9\u3002 const element = < […]<\/p>\n","protected":false},"author":1470,"featured_media":207359,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-207358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/207358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=207358"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/207358\/revisions"}],"predecessor-version":[{"id":207362,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/207358\/revisions\/207362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/207359"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=207358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=207358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=207358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}