\u6570\u636e\u81ea\u9876\u5411\u4e0b\u6d41\u52a8<\/strong><\/div>\n\u7236\u7ec4\u4ef6\u6216\u5b50\u7ec4\u4ef6\u90fd\u4e0d\u80fd\u77e5\u9053\u67d0\u4e2a\u7ec4\u4ef6\u662f\u6709\u72b6\u6001\u8fd8\u662f\u65e0\u72b6\u6001\uff0c\u5e76\u4e14\u5b83\u4eec\u4e0d\u5e94\u8be5\u5173\u5fc3\u67d0\u7ec4\u4ef6\u662f\u88ab\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u51fd\u6570\u8fd8\u662f\u4e00\u4e2a\u7c7b\u3002
\n\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u72b6\u6001\u901a\u5e38\u88ab\u79f0\u4e3a\u5c40\u90e8\u6216\u5c01\u88c5\u3002 \u9664\u4e86\u62e5\u6709\u5e76\u8bbe\u7f6e\u5b83\u7684\u7ec4\u4ef6\u5916\uff0c\u5176\u5b83\u7ec4\u4ef6\u4e0d\u53ef\u8bbf\u95ee\u3002
\n\u4ee5\u4e0b\u5b9e\u4f8b\u4e2d FormattedDate \u7ec4\u4ef6\u5c06\u5728\u5176\u5c5e\u6027\u4e2d\u63a5\u6536\u5230 date \u503c\uff0c\u5e76\u4e14\u4e0d\u77e5\u9053\u5b83\u662f\u6765\u81ea Clock \u72b6\u6001\u3001\u8fd8\u662f\u6765\u81ea Clock \u7684\u5c5e\u6027\u3001\u4ea6\u6216\u624b\u5de5\u8f93\u5165\uff1a<\/p>\n
React \u5b9e\u4f8b<\/p>\n
\r\nfunction FormattedDate(props) {\r\n return <h2>\u73b0\u5728\u662f {props.date.toLocaleTimeString()}.<\/h2>;\r\n}\r\n \r\nclass Clock extends React.Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {date: new Date()};\r\n }\r\n \r\n componentDidMount() {\r\n this.timerID = setInterval(\r\n () => this.tick(),\r\n 1000\r\n );\r\n }\r\n \r\n componentWillUnmount() {\r\n clearInterval(this.timerID);\r\n }\r\n \r\n tick() {\r\n this.setState({\r\n date: new Date()\r\n });\r\n }\r\n \r\n render() {\r\n return (\r\n <div>\r\n <h1>Hello, world!<\/h1>\r\n <FormattedDate date={this.state.date} \/>\r\n <\/div>\r\n );\r\n }\r\n}\r\n \r\nReactDOM.render(\r\n <Clock \/>,\r\n document.getElementById('example')\r\n);\r\n<\/pre>\n\u8fd9\u901a\u5e38\u88ab\u79f0\u4e3a\u81ea\u9876\u5411\u4e0b\u6216\u5355\u5411\u6570\u636e\u6d41\u3002 \u4efb\u4f55\u72b6\u6001\u59cb\u7ec8\u7531\u67d0\u4e9b\u7279\u5b9a\u7ec4\u4ef6\u6240\u6709\uff0c\u5e76\u4e14\u4ece\u8be5\u72b6\u6001\u5bfc\u51fa\u7684\u4efb\u4f55\u6570\u636e\u6216 UI \u53ea\u80fd\u5f71\u54cd\u6811\u4e2d\u4e0b\u65b9\u7684\u7ec4\u4ef6\u3002
\n\u5982\u679c\u4f60\u60f3\u8c61\u4e00\u4e2a\u7ec4\u4ef6\u6811\u4f5c\u4e3a\u5c5e\u6027\u7684\u7011\u5e03\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u72b6\u6001\u5c31\u50cf\u4e00\u4e2a\u989d\u5916\u7684\u6c34\u6e90\uff0c\u5b83\u8fde\u63a5\u5728\u4e00\u4e2a\u4efb\u610f\u70b9\uff0c\u4f46\u4e5f\u6d41\u4e0b\u6765\u3002
\n\u4e3a\u4e86\u8868\u660e\u6240\u6709\u7ec4\u4ef6\u90fd\u662f\u771f\u6b63\u9694\u79bb\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a App \u7ec4\u4ef6\uff0c\u5b83\u6e32\u67d3\u4e09\u4e2aClock\uff1a<\/p>\n
React \u5b9e\u4f8b<\/p>\n
\r\nfunction FormattedDate(props) {\r\n return <h2>\u73b0\u5728\u662f {props.date.toLocaleTimeString()}.<\/h2>;\r\n}\r\n \r\nclass Clock extends React.Component {\r\n constructor(props) {\r\n super(props);\r\n this.state = {date: new Date()};\r\n }\r\n \r\n componentDidMount() {\r\n this.timerID = setInterval(\r\n () => this.tick(),\r\n 1000\r\n );\r\n }\r\n \r\n componentWillUnmount() {\r\n clearInterval(this.timerID);\r\n }\r\n \r\n tick() {\r\n this.setState({\r\n date: new Date()\r\n });\r\n }\r\n \r\n render() {\r\n return (\r\n <div>\r\n <h1>Hello, world!<\/h1>\r\n <FormattedDate date={this.state.date} \/>\r\n <\/div>\r\n );\r\n }\r\n}\r\n \r\nfunction App() {\r\n return (\r\n <div>\r\n <Clock \/>\r\n <Clock \/>\r\n <Clock \/>\r\n <\/div>\r\n );\r\n}\r\n \r\nReactDOM.render(<App \/>, document.getElementById('example'));<\/pre>\n\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d\u6bcf\u4e2a Clock \u7ec4\u4ef6\u90fd\u5efa\u7acb\u4e86\u81ea\u5df1\u7684\u5b9a\u65f6\u5668\u5e76\u4e14\u72ec\u7acb\u66f4\u65b0\u3002
\n\u5728 React \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u7ec4\u4ef6\u662f\u6709\u72b6\u6001\u8fd8\u662f\u65e0\u72b6\u6001\u88ab\u8ba4\u4e3a\u662f\u53ef\u80fd\u968f\u65f6\u95f4\u800c\u53d8\u5316\u7684\u7ec4\u4ef6\u7684\u5b9e\u73b0\u7ec6\u8282\u3002
\n\u6211\u4eec\u53ef\u4ee5\u5728\u6709\u72b6\u6001\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u65e0\u72b6\u6001\u7ec4\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u5728\u65e0\u72b6\u6001\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u6709\u72b6\u6001\u7ec4\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
React \u628a\u7ec4\u4ef6\u770b\u6210\u662f\u4e00\u4e2a\u72b6\u6001\u673a\uff08State Machines\uff09\u3002\u901a\u8fc7\u4e0e\u7528\u6237\u7684\u4ea4\u4e92\uff0c\u5b9e\u73b0\u4e0d\u540c\u72b6\u6001\uff0c\u7136\u540e\u6e32\u67d3 […]<\/p>\n","protected":false},"author":321,"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-207526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=207526"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207526\/revisions"}],"predecessor-version":[{"id":207529,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/207526\/revisions\/207529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/207359"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=207526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=207526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=207526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}