{"id":4740,"date":"2023-01-04T18:02:41","date_gmt":"2023-01-04T10:02:41","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4740"},"modified":"2023-01-04T18:02:41","modified_gmt":"2023-01-04T10:02:41","slug":"%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e3%80%8cerroracomponentischanginganuncontrolledtextareatobecontrolled%e3%80%8d%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e8%a7%a3%e6%b1%bareact-js%e4%b8%ad%e3%80%8cerroracomponentischanginganuncontrolledtextareatobecontrolled%e3%80%8d%e7%9a%84%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u89e3\u6c7aReact.js\u4e2d\u300cError:Acomponentischanginganuncontrolledtextareatobecontrolled\u300d\u7684\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, Error, Textarea, Controlled, Uncontrolled\"><\/p>\n<h1>\u89e3\u6c7a React.js &#8220;Error: A component is changing an uncontrolled textarea to be controlled&#8221; \u932f\u8aa4<\/h1>\n<p>React.js \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u7684 JavaScript \u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5feb\u901f\u69cb\u5efa\u51fa\u9ad8\u54c1\u8cea\u7684\u61c9\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u5728\u958b\u767c React.js \u61c9\u7528\u7a0b\u5e8f\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u554f\u984c\uff0c\u5176\u4e2d\u4e00\u500b\u662f &#8220;Error: A component is changing an uncontrolled textarea to be controlled&#8221; \u932f\u8aa4\u3002<\/p>\n<p>\u9019\u500b\u932f\u8aa4\u7684\u539f\u56e0\u662f\u56e0\u70ba\u958b\u767c\u8005\u5728\u4f7f\u7528 React.js \u6642\uff0c\u6c92\u6709\u6b63\u78ba\u5730\u5c07 textarea \u63a7\u4ef6\u8a2d\u7f6e\u70ba\u53d7\u63a7\u6a21\u5f0f\u3002\u53d7\u63a7\u6a21\u5f0f\u610f\u5473\u8457\uff0c\u7576\u7528\u6236\u5728 textarea \u4e2d\u8f38\u5165\u6587\u672c\u6642\uff0cReact.js \u6703\u66f4\u65b0\u5176\u72c0\u614b\uff0c\u4ee5\u4fbf\u61c9\u7528\u7a0b\u5e8f\u53ef\u4ee5\u6aa2\u67e5\u7528\u6236\u8f38\u5165\u7684\u6587\u672c\u662f\u5426\u7b26\u5408\u61c9\u7528\u7a0b\u5e8f\u7684\u8981\u6c42\u3002<\/p>\n<p>\u8981\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u958b\u767c\u8005\u9700\u8981\u5728\u6e32\u67d3 textarea \u63a7\u4ef6\u6642\uff0c\u5c07\u5176\u8a2d\u7f6e\u70ba\u53d7\u63a7\u6a21\u5f0f\u3002\u9019\u53ef\u4ee5\u901a\u904e\u5728 textarea \u63a7\u4ef6\u4e0a\u6dfb\u52a0\u4e00\u500b value \u5c6c\u6027\u4f86\u5be6\u73fe\uff0cvalue \u5c6c\u6027\u53ef\u4ee5\u7528\u65bc\u6307\u5b9a textarea \u63a7\u4ef6\u7684\u521d\u59cb\u503c\u3002<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u8a2d\u7f6e textarea \u63a7\u4ef6\u70ba\u53d7\u63a7\u6a21\u5f0f\n<textarea value=\"This is the initial value\"><\/textarea>\n<\/pre>\n<p>\u6b64\u5916\uff0c\u958b\u767c\u8005\u9084\u9700\u8981\u70ba textarea \u63a7\u4ef6\u6dfb\u52a0\u4e00\u500b onChange \u4e8b\u4ef6\u4f86\u66f4\u65b0\u5176\u72c0\u614b\uff0c\u4ee5\u4fbf\u61c9\u7528\u7a0b\u5e8f\u53ef\u4ee5\u6aa2\u67e5\u7528\u6236\u8f38\u5165\u7684\u6587\u672c\u662f\u5426\u7b26\u5408\u61c9\u7528\u7a0b\u5e8f\u7684\u8981\u6c42\u3002<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u66f4\u65b0 textarea \u63a7\u4ef6\u7684\u72c0\u614b\n<textarea value=\"This is the initial value\" onChange={this.handleChange}><\/textarea>\n<\/pre>\n<p>\u6700\u5f8c\uff0c\u958b\u767c\u8005\u9084\u9700\u8981\u5728\u61c9\u7528\u7a0b\u5e8f\u4e2d\u5b9a\u7fa9\u4e00\u500b handleChange \u65b9\u6cd5\uff0c\u8a72\u65b9\u6cd5\u5c07\u6703\u5728\u7528\u6236\u5728 textarea \u4e2d\u8f38\u5165\u6587\u672c\u6642\u8abf\u7528\uff0c\u4ee5\u66f4\u65b0\u61c9\u7528\u7a0b\u5e8f\u7684\u72c0\u614b\u3002<\/p>\n<pre class=\"brush: javascript\">\n\/\/ \u5b9a\u7fa9 handleChange \u65b9\u6cd5\nhandleChange(event) {\n  this.setState({value: event.target.value});\n}\n<\/pre>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u958b\u767c\u8005\u5c31\u53ef\u4ee5\u89e3\u6c7a React.js &#8220;Error: A component is changing an uncontrolled textarea to be controlled&#8221; \u932f\u8aa4\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u958b\u767c React.js \u61c9\u7528\u7a0b\u5e8f\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230 &#8220;Error: A component is changing an uncontrolled textarea to be controlled&#8221; \u932f\u8aa4\u3002\u89e3\u6c7a\u8a72\u932f\u8aa4\u7684\u65b9\u6cd5\u662f\uff0c\u5728\u6e32\u67d3 textarea \u63a7\u4ef6\u6642\uff0c\u5c07\u5176\u8a2d\u7f6e\u70ba\u53d7\u63a7\u6a21\u5f0f\uff0c\u4e26\u4e14\u70ba textarea \u63a7\u4ef6\u6dfb\u52a0\u4e00\u500b onChange \u4e8b\u4ef6\uff0c\u4ee5\u53ca\u4e00\u500b handleChange \u65b9\u6cd5\u4f86\u66f4\u65b0\u61c9\u7528\u7a0b\u5e8f\u7684\u72c0\u614b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7aReact.js\u4e2d\u300cError:Acomponentischanginganuncontrolledtextareatobecontrolled\u300d\u7684\u554f\u984c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u6709\u7528\u7684\u6280\u5de7\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u8655\u7406\u9019\u500b\u554f\u984c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-4740","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1es","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=4740"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4740\/revisions"}],"predecessor-version":[{"id":4741,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4740\/revisions\/4741"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}