{"id":31386,"date":"2024-11-25T16:01:26","date_gmt":"2024-11-25T08:01:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31386\/"},"modified":"2024-11-25T16:01:26","modified_gmt":"2024-11-25T08:01:26","slug":"react%e7%bb%84%e4%bb%b6refs%e8%af%a5%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31386\/","title":{"rendered":"React\u7ec4\u4ef6refs\u8be5\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"<p style=\"text-align: left\">\u8fd9\u6b21\u7ed9\u5927\u5bb6\u5e26\u6765React\u7ec4\u4ef6refs\u8be5\u600e\u4e48\u4f7f\u7528\uff0cReact\u7ec4\u4ef6refs\u4f7f\u7528\u7684\u6709\u54ea\u4e9b\uff0c\u4e0b\u9762\u5c31\u662f\u5b9e\u6218\u6848\u4f8b\uff0c\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u3002<\/p>\n<p style=\"text-align: left\">ref\u987e\u540d\u601d\u4e49\u6211\u4eec\u77e5\u9053\uff0c\u5176\u5b9e\u5b83\u5c31\u53ef\u4ee5\u88ab\u770b\u5ea7\u662f\u4e00\u4e2a\u7ec4\u4ef6\u7684\u53c2\u8003\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u662f\u4e00\u4e2a\u6807\u8bc6\u3002\u4f5c\u4e3a\u7ec4\u4ef6\u7684\u5c5e\u6027\uff0c\u5176\u5c5e\u6027\u503c\u53ef\u4ee5\u662f\u4e00\u4e2a\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n<p style=\"text-align: left\">\u5176\u5b9e\uff0cref\u7684\u4f7f\u7528\u4e0d\u662f\u5fc5\u987b\u7684\u3002\u5373\u4f7f\u662f\u5728\u5176\u9002\u7528\u7684\u573a\u666f\u4e2d\u4e5f\u4e0d\u662f\u975e\u7528\u4e0d\u53ef\u7684\uff0c\u56e0\u4e3a\u4f7f\u7528ref\u5b9e\u73b0\u7684\u529f\u80fd\u540c\u6837\u53ef\u4ee5\u8f6c\u5316\u6210\u5176\u4ed6\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4f46\u662f\uff0c\u65e2\u7136ref\u6709\u5176\u9002\u7528\u7684\u573a\u666f\uff0c\u90a3\u4e5f\u5c31\u662f\u8bf4ref\u81ea\u6709\u5176\u4f18\u52bf\u3002\u5173\u4e8e\u8fd9\u4e00\u70b9\u548cref\u7684\u9002\u7528\u573a\u666f\uff0c\u5b98\u65b9\u6587\u6863\u4e2d\u662f\u8fd9\u6837\u8bf4\u7684\uff1a<\/p>\n<p style=\"text-align: left\">\u5728\u4ece render \u65b9\u6cd5\u4e2d\u8fd4\u56de UI \u7ed3\u6784\u4e4b\u540e\uff0c\u4f60\u53ef\u80fd\u60f3\u51b2\u51fa React \u865a\u62df DOM \u7684\u9650\u5236\uff0c\u5728 render \u8fd4\u56de\u7684\u7ec4\u4ef6\u5b9e\u4f8b\u4e0a\u8c03\u7528\u67d0\u4e9b\u65b9\u6cd5\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u8fd9\u6837\u505a\u5bf9\u4e8e\u5e94\u7528\u4e2d\u7684\u6570\u636e\u6d41\u52a8\u662f\u4e0d\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u6d3b\u8dc3\u7684\u6570\u636e\uff08 Reactive data \uff09\u6d41\u603b\u662f\u786e\u4fdd\u6700\u65b0\u7684 props \u88ab\u4f20\u9012\u5230\u6bcf\u4e00\u4e2a\u4ece render() \u8f93\u51fa\u7684\u5b50\u7ea7\u4e2d\u53bb\u3002\u7136\u800c\uff0c\u4ecd\u7136\u6709\u51e0\u4e2a\u573a\u666f\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u662f\u5fc5\u987b\u7684\uff0c\u6216\u8005\u8bf4\u662f\u6709\u76ca\u7684\uff1a\u67e5\u627e\u6e32\u67d3\u51fa\u7684\u7ec4\u4ef6\u7684DOM\u6807\u8bb0\uff08\u53ef\u4ee5\u8ba4\u4e3a\u662fDOM\u7684\u6807\u8bc6ID\uff09\uff0c\u5728\u4e00\u4e2a\u5927\u578b\u7684\u975eReact\u5e94\u7528\u4e2d\u4f7f\u7528React\u7ec4\u4ef6\u6216\u8005\u662f\u5c06\u4f60\u73b0\u6709\u7684\u4ee3\u7801\u8f6c\u5316\u6210React\u3002<\/p>\n<p style=\"text-align: left\">\u4e0b\u9762\u6211\u4eec\u6765\u770b\u8fd9\u6837\u7684\u4e00\u4e2a\u573a\u666f\uff08\u4e0b\u9762\u7684\u4f8b\u5b50\u7ecf\u5e38\u88ab\u7528\u4e8eref\u7684\u8bb2\u89e3\uff0c\u53ef\u89c1\u4e0b\u9762\u63cf\u8ff0\u7684\u573a\u666f\u5e94\u8be5\u662f\u6bd4\u8f83\u7ecf\u5178\u7684\uff09\uff1a\u901a\u8fc7\u67d0\u4e2a\u4e8b\u4ef6\u4f7f\u5143\u7d20\u7684\u503c\u88ab\u8bbe\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u8be5\u5143\u7d20\u83b7\u5f97\u7126\u70b9\u3002<\/p>\n<pre>var App = React.createClass({\r\n  getInitialState: function() {\r\n   return {userInput: ''};\r\n  },\r\n  handleChange: function(e) {\r\n   this.setState({userInput: e.target.value});\r\n  },\r\n  clearAndFocusInput: function() {\r\n   this.setState({userInput: ''}); \/\/ \u8bbe\u7f6e\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32\r\n        \/\/\u8fd9\u91cc\u60f3\u8981\u5b9e\u73b0\u83b7\u5f97\u7126\u70b9   \r\n  },\r\n  render: function() {\r\n   return (\r\n    &lt;p&gt;\r\n     &lt;input\r\n      value={this.state.userInput}\r\n      onChange={this.handleChange}\r\n     \/&gt;\r\n          &lt;input type=\"button\"\r\n           value=\"Reset And Focus\"\r\n           onClick={this.clearAndFocusInput}\r\n        \/&gt;\r\n    &lt;\/p&gt;\r\n   );\r\n  }\r\n });<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u5728\u4e0a\u9762\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u5b9e\u73b0\u4e86\u70b9\u51fb\u6309\u94ae\u901a\u77e5input\u5143\u7d20\u5c06\u503c\u8bbe\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u4f46\u662f\u8fd8\u6ca1\u6709\u5b9e\u73b0\u4f7finput\u5143\u7d20\u83b7\u5f97\u7126\u70b9\u3002\u8fd9\u5b9e\u73b0\u8d77\u6765\u6709\u4e9b\u56f0\u96be\uff0c\u56e0\u4e3a\u5728render()\u4e2d\u8fd4\u56de\u7684\u5e76\u4e0d\u662f\u5b9e\u9645\u7684\u5b50\u7ec4\u4ef6\u7684\u7ec4\u5408\uff0c\u4ec5\u4ec5\u662f\u4e00\u4e2a\u7279\u5b9a\u65f6\u95f4\u7279\u5b9a\u5b9e\u4f8b\u7684\u63cf\u8ff0\u3002\u8fd9\u53e5\u8bdd\u611f\u89c9\u633a\u7ed5\u7684\uff0c\u5176\u5b9erender\u8fd4\u56de\u7684\u662f\u865a\u62df\u7684DOM\uff0c\u5e76\u4e0d\u662f\u771f\u5b9e\u7684DOM\u3002\u56e0\u6b64\u6211\u4eec\u4e0d\u9700\u8981\u4ec5\u4ec5\u7740\u773c\u4e8e\u90a3\u4e9b\u4ecerender()\u4e2d\u8fd4\u56de\u7684\u90a3\u4e9b\u7ec4\u4ef6\u3002<\/p>\n<p style=\"text-align: left\">\u90a3\u8bf4\u5230\u8fd9\uff0c\u5bf9\u4e8e\u6211\u4eec\u5982\u4f55\u5b9e\u73b0\u83b7\u5f97\u7126\u70b9\u5e76\u6ca1\u6709\u592a\u5927\u7684\u5e2e\u52a9\u3002\u8981\u60f3\u5b9e\u73b0\u83b7\u5f97\u7126\u70b9\u8fd9\u4e2a\u529f\u80fd\u6211\u4eec\u9700\u8981\u501f\u52a9ref\u6765\u5b9e\u73b0\u3002\u4e0a\u9762\u6211\u4eec\u63d0\u5230\u8fc7ref\u7684\u503c\u6709\u4e24\u79cd\u7c7b\u578b\uff0c\u4e00\u79cd\u662f\u5b57\u7b26\u4e32\u3001\u4e00\u79cd\u662f\u3002<\/p>\n<p style=\"text-align: left\"><strong>ref\u5b57\u7b26\u4e32\u4e0a\u5c5e\u6027<\/strong><\/p>\n<p style=\"text-align: left\">React\u652f\u6301\u4e00\u4e2a\u7279\u6b8a\u7684\u5c5e\u6027\uff0c\u4f60\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u5c5e\u6027\u52a0\u5728\u4efb\u4f55\u901a\u8fc7render()\u8fd4\u56de\u7684\u7ec4\u4ef6\u4e2d\u3002\u8fd9\u4e5f\u5c31\u662f\u8bf4\u5bf9render()\u8fd4\u56de\u7684\u7ec4\u4ef6\u8fdb\u884c\u4e00\u4e2a\u6807\u8bb0\uff0c\u53ef\u4ee5\u65b9\u4fbf\u7684\u5b9a\u4f4d\u7684\u8fd9\u4e2a\u7ec4\u4ef6\u5b9e\u4f8b\u3002\u8fd9\u5c31\u662fref\u7684\u4f5c\u7528\u3002<\/p>\n<p style=\"text-align: left\">ref\u7684\u5f62\u5f0f\u5982\u4e0b<\/p>\n<pre>&lt;input ref=\"myInput\" \/&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u8981\u60f3\u8bbf\u95ee\u8fd9\u4e2a\u5b9e\u4f8b\uff0c\u53ef\u4ee5\u901a\u8fc7this.refs\u6765\u8bbf\u95ee\uff1a<\/p>\n<pre>this.refs.myInput<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u5148\u524d\u7248\u672c\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7React.findDOMNode(this.refs.myInput)\u6765\u8bbf\u95ee\u7ec4\u4ef6\u7684DOM\u3002\u4f46\u662f\u73b0\u5728\uff0c\u5df2\u7ecf\u653e\u5f03\u4e86findDOMNode\u51fd\u6570\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528this.refs.myInput\u6765\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n<p style=\"text-align: left\">ref\u56de\u8c03\u51fd\u6570<\/p>\n<p style=\"text-align: left\">ref\u5c5e\u6027\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u800c\u4e0d\u662f\u4e00\u4e2a\u540d\u5b57\u3002&nbsp;&nbsp; \u8fd9\u4e2a\u51fd\u6570\u5c06\u8981\u5728\u7ec4\u4ef6\u88ab\u6302\u8f7d\u4e4b\u540e\u7acb\u5373\u6267\u884c\u3002\u8fd9\u4e2a\u53c2\u7167\u7684\u7ec4\u4ef6\u5c06\u4f1a\u4f5c\u4e3a\u8be5\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u7acb\u5373\u4f7f\u7528\u8fd9\u4e2a\u7ec4\u4ef6\u53c2\u6570\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u5c06\u5176\u4fdd\u5b58\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<\/p>\n<p style=\"text-align: left\">\u5176\u5f62\u5f0f\u4e5f\u6bd4\u8f83\u7b80\u5355\uff1a<\/p>\n<pre>render: function() {\r\n  return &lt;TextInput ref={(c) =&gt; this._input = c} } \/&gt;;\r\n},\r\ncomponentDidMount: function() {\r\n  this._input.focus();\r\n},<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u6216\u8005\u662f<\/p>\n<pre>render: function() {\r\n  return (\r\n   &lt;TextInput\r\n    ref={function(input) {\r\n     if (input != null) {\r\n      input.focus();\r\n     }\r\n    }} \/&gt;\r\n  );\r\n},<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u5f53\u8fd9\u4e2a\u53c2\u7167\u7ec4\u4ef6\u88ab\u5378\u8f7d\u5e76\u4e14\u8fd9\u4e2aref\u6539\u53d8\u7684\u65f6\u5019\uff0c\u5148\u524d\u7684ref\u7684\u53c2\u6570\u503c\u5c06\u4e3anull\u3002\u8fd9\u5c06\u6709\u6548\u7684\u9632\u6b62\u4e86\u5185\u5b58\u7684\u6cc4\u9732\u3002\u6240\u4ee5\u5728\u4e0a\u9762\u4ee3\u7801\u4e2d\u4f1a\u6709if\u5224\u65ad\uff1a<\/p>\n<pre>if(input != null){\r\n     input.focus();\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u4e0a\u9762\u4ecb\u7ecd\u4e86ref\u7684\u4f7f\u7528\u573a\u666f\u548c\u65b9\u6cd5\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u5c06\u4e0a\u9762\u7684\u4f8b\u5b50\u6765\u8865\u5145\u5b8c\u6574\uff0c\u4ece\u800c\u5b9e\u73b0\u83b7\u5f97\u7126\u70b9\u7684\u529f\u80fd<\/p>\n<pre>var App = React.createClass({\r\n  getInitialState: function() {\r\n    return {userInput: ''};\r\n  },\r\n  handleChange: function(e) {\r\n    this.setState({userInput: e.target.value});\r\n  },\r\n  clearAndFocusInput: function() {\r\n    this.setState({userInput: ''}); \/\/ Clear the input\r\n    \/\/ We wish to focus the &lt;input \/&gt; now!\r\n    if (this.refs.myTextInput !== null) {\r\n      this.refs.myTextInput.focus();\r\n    }\r\n  },\r\n  render: function() {\r\n    return (\r\n      &lt;p&gt;\r\n        &lt;input\r\n          value={this.state.userInput}\r\n          onChange={this.handleChange}\r\n          ref=\u201dmyTextInput\u201d   \r\n                     \/&gt;\r\n        &lt;input\r\n          type=\"button\"\r\n          value=\"Reset And Focus\"\r\n          onClick={this.clearAndFocusInput}\r\n          \/&gt;\r\n      &lt;\/p&gt;\r\n    );\r\n  }\r\n});\r\nReactDOM.render(\r\n  &lt;App \/&gt;,\r\n  document.getElementById('content')\r\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align: left\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c render \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a \u5b9e\u4f8b\u7684\u63cf\u8ff0\u3002\u4f46\u662f\u771f\u6b63\u7684\u5b9e\u4f8b\u901a\u8fc7 this.refs. myTextInput\u83b7\u53d6\u3002\u53ea\u8981 render \u8fd4\u56de\u7684\u67d0\u4e2a\u5b50\u7ec4\u4ef6\u5e26\u6709 ref=&#8221;myTextInput&#8221; \uff0cthis.refs. myTextInput\u5c31\u4f1a\u83b7\u53d6\u5230\u6b63\u786e\u7684\u5b9e\u4f8b\u3002<\/p>\n<p>\u76f8\u4fe1\u770b\u4e86\u672c\u6587\u6848\u4f8b\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u65b9\u6cd5\uff0c\u66f4\u591a\u7cbe\u5f69\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n<p>\u63a8\u8350\u9605\u8bfb\uff1a<\/p>\n<p><\/p>\n<p><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fReact\u7ec4\u4ef6refs\u8be5\u600e\u4e48\u4f7f\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u6b21\u7ed9\u5927\u5bb6\u5e26\u6765React\u7ec4\u4ef6refs\u8be5\u600e\u4e48\u4f7f\u7528\uff0cReact\u7ec4\u4ef6refs\u4f7f\u7528\u7684\u6709\u54ea\u4e9b\uff0c\u4e0b\u9762\u5c31\u662f\u5b9e\u6218\u6848\u4f8b\uff0c\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u3002 ref\u987e\u540d\u601d\u4e49\u6211\u4eec\u77e5\u9053\uff0c\u5176\u5b9e\u5b83\u5c31\u53ef\u4ee5\u88ab\u770b\u5ea7\u662f\u4e00\u4e2a\u7ec4\u4ef6\u7684\u53c2\u8003\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u662f\u4e00\u4e2a\u6807\u8bc6\u3002\u4f5c\u4e3a\u7ec4\u4ef6\u7684\u5c5e\u6027\uff0c\u5176\u5c5e\u6027\u503c\u53ef\u4ee5\u662f\u4e00\u4e2a\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u51fd\u6570\u3002 \u5176\u5b9e\uff0cref\u7684\u4f7f\u7528\u4e0d\u662f\u5fc5\u987b\u7684\u3002\u5373\u4f7f\u662f\u5728\u5176\u9002\u7528\u7684\u573a\u666f\u4e2d\u4e5f\u4e0d\u662f\u975e\u7528\u4e0d\u53ef\u7684\uff0c\u56e0\u4e3a\u4f7f\u7528ref\u5b9e\u73b0\u7684\u529f\u80fd\u540c\u6837\u53ef\u4ee5\u8f6c\u5316\u6210\u5176\u4ed6\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4f46\u662f\uff0c\u65e2\u7136ref\u6709\u5176\u9002\u7528\u7684\u573a\u666f\uff0c\u90a3\u4e5f\u5c31\u662f\u8bf4ref\u81ea\u6709\u5176\u4f18\u52bf\u3002\u5173\u4e8e\u8fd9\u4e00\u70b9\u548cref\u7684\u9002\u7528\u573a\u666f\uff0c\u5b98\u65b9\u6587\u6863\u4e2d\u662f\u8fd9\u6837\u8bf4\u7684\uff1a \u5728\u4ece render \u65b9\u6cd5\u4e2d\u8fd4\u56de UI \u7ed3\u6784\u4e4b\u540e\uff0c\u4f60\u53ef\u80fd\u60f3\u51b2\u51fa React \u865a\u62df DOM \u7684\u9650\u5236\uff0c\u5728 render \u8fd4\u56de\u7684\u7ec4\u4ef6\u5b9e\u4f8b\u4e0a\u8c03\u7528\u67d0\u4e9b\u65b9\u6cd5\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u8fd9\u6837\u505a\u5bf9\u4e8e\u5e94\u7528\u4e2d\u7684\u6570\u636e\u6d41\u52a8\u662f\u4e0d\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u6d3b\u8dc3\u7684\u6570\u636e\uff08 Reactive data \uff09\u6d41\u603b\u662f\u786e\u4fdd\u6700\u65b0\u7684 props \u88ab\u4f20\u9012\u5230\u6bcf\u4e00\u4e2a\u4ece render() \u8f93\u51fa\u7684\u5b50\u7ea7\u4e2d\u53bb\u3002\u7136\u800c\uff0c\u4ecd\u7136\u6709\u51e0\u4e2a\u573a\u666f\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u662f\u5fc5\u987b\u7684\uff0c\u6216\u8005\u8bf4\u662f\u6709\u76ca\u7684\uff1a\u67e5\u627e\u6e32\u67d3\u51fa\u7684\u7ec4\u4ef6\u7684DOM\u6807\u8bb0\uff08\u53ef\u4ee5\u8ba4\u4e3a\u662fDOM\u7684\u6807\u8bc6ID\uff09\uff0c\u5728\u4e00\u4e2a\u5927\u578b\u7684\u975eReact\u5e94\u7528\u4e2d\u4f7f\u7528React\u7ec4\u4ef6\u6216\u8005\u662f\u5c06\u4f60\u73b0\u6709\u7684\u4ee3\u7801\u8f6c\u5316\u6210React\u3002 \u4e0b\u9762\u6211\u4eec\u6765\u770b\u8fd9\u6837\u7684\u4e00\u4e2a\u573a\u666f\uff08\u4e0b\u9762\u7684\u4f8b\u5b50\u7ecf\u5e38\u88ab\u7528\u4e8eref\u7684\u8bb2\u89e3\uff0c\u53ef\u89c1\u4e0b\u9762\u63cf\u8ff0\u7684\u573a\u666f\u5e94\u8be5\u662f\u6bd4\u8f83\u7ecf\u5178\u7684\uff09\uff1a\u901a\u8fc7\u67d0\u4e2a\u4e8b\u4ef6\u4f7f\u5143\u7d20\u7684\u503c\u88ab\u8bbe\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u4f7f\u8be5\u5143\u7d20\u83b7\u5f97\u7126\u70b9\u3002 var App = React.createClass({ getInitialState: function() { return {userInput: &#8221;}; }, handleChange: function(e) { this.setState({userInput: e.target.value}); }, clearAndFocusInput: function() { this.setState({userInput: &#8221;}); \/\/ \u8bbe\u7f6e\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32 \/\/\u8fd9\u91cc\u60f3\u8981\u5b9e\u73b0\u83b7\u5f97\u7126\u70b9 }, render: function() { return ( &lt;p&gt; &lt;input [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-31386","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31386"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31386\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}