{"id":4729,"date":"2023-01-04T17:56:32","date_gmt":"2023-01-04T09:56:32","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4729"},"modified":"2023-01-04T17:56:32","modified_gmt":"2023-01-04T09:56:32","slug":"%e8%a7%a3%e6%b1%bareact-js%e4%b8%aderroracomponentischangingacontrolledinputoftypetexttobeuncontrolled%e7%9a%84%e9%8c%af%e8%aa%a4","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e8%a7%a3%e6%b1%bareact-js%e4%b8%aderroracomponentischangingacontrolledinputoftypetexttobeuncontrolled%e7%9a%84%e9%8c%af%e8%aa%a4\/","title":{"rendered":"\u89e3\u6c7aReact.js\u4e2d&#8221;Error:Acomponentischangingacontrolledinputoftypetexttobeuncontrolled&#8221;\u7684\u932f\u8aa4"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, Error, Controlled Input, Uncontrolled\"><\/p>\n<h1>\u89e3\u6c7a React.js &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4<\/h1>\n<p>React.js \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u7aef\u61c9\u7528\u7a0b\u5e8f\u7684 JavaScript \u5eab\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u69cb\u5efa\u9ad8\u6027\u80fd\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u5728\u4f7f\u7528 React.js \u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4e00\u500b\u5e38\u898b\u7684\u932f\u8aa4\uff1a\u201cError: A component is changing a controlled input of type text to be uncontrolled\u201d\u3002\u672c\u6587\u5c07\u89e3\u91cb\u9019\u500b\u932f\u8aa4\u7684\u539f\u56e0\uff0c\u4ee5\u53ca\u5982\u4f55\u89e3\u6c7a\u5b83\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u53d7\u63a7\u8f38\u5165\uff1f<\/h2>\n<p>\u53d7\u63a7\u8f38\u5165\u662f\u6307 React.js \u5c07\u8f38\u5165\u63a7\u4ef6\u7684\u503c\u8207\u5176\u72c0\u614b\u7d81\u5b9a\u5728\u4e00\u8d77\u7684\u4e00\u7a2e\u6280\u8853\u3002\u53d7\u63a7\u8f38\u5165\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u800c\u4e0d\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8a2d\u4f60\u6709\u4e00\u500b\u6587\u672c\u6846\uff0c\u5b83\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u800c\u4e0d\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\uff1a<\/p>\n<pre class=\"brush: javascript\">\n<input type=\"text\" value={this.state.value} onChange={this.handleChange} \/>\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6587\u672c\u6846\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u56e0\u70ba\u5b83\u662f\u7531 this.state.value \u5c6c\u6027\u63a7\u5236\u7684\u3002\u7576\u7528\u6236\u8f38\u5165\u6587\u672c\u6846\u6642\uff0cReact.js \u5c07\u8abf\u7528 handleChange \u65b9\u6cd5\u66f4\u65b0 this.state.value \u5c6c\u6027\uff0c\u4ee5\u66f4\u65b0\u6587\u672c\u6846\u7684\u503c\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u4e0d\u53d7\u63a7\u8f38\u5165\uff1f<\/h2>\n<p>\u4e0d\u53d7\u63a7\u8f38\u5165\u662f\u6307 React.js \u4e0d\u6703\u5c07\u8f38\u5165\u63a7\u4ef6\u7684\u503c\u8207\u5176\u72c0\u614b\u7d81\u5b9a\u5728\u4e00\u8d77\u7684\u4e00\u7a2e\u6280\u8853\u3002\u4e0d\u53d7\u63a7\u8f38\u5165\u7684\u503c\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\uff0c\u800c\u4e0d\u662f\u7531 React.js \u63a7\u5236\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8a2d\u4f60\u6709\u4e00\u500b\u6587\u672c\u6846\uff0c\u5b83\u7684\u503c\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\uff0c\u800c\u4e0d\u662f\u7531 React.js \u63a7\u5236\u7684\uff1a<\/p>\n<pre class=\"brush: javascript\">\n<input type=\"text\" defaultValue=\"Hello World\" \/>\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6587\u672c\u6846\u7684\u503c\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\uff0c\u56e0\u70ba\u5b83\u662f\u7531 defaultValue \u5c6c\u6027\u63a7\u5236\u7684\u3002\u7576\u7528\u6236\u8f38\u5165\u6587\u672c\u6846\u6642\uff0cReact.js \u4e0d\u6703\u66f4\u65b0 defaultValue \u5c6c\u6027\uff0c\u56e0\u6b64\u6587\u672c\u6846\u7684\u503c\u5c07\u4fdd\u6301\u4e0d\u8b8a\u3002<\/p>\n<h2>\u70ba\u4ec0\u9ebc\u6703\u51fa\u73fe &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\uff1f<\/h2>\n<p>\u9019\u500b\u932f\u8aa4\u6703\u51fa\u73fe\uff0c\u662f\u56e0\u70ba\u4f60\u6b63\u5728\u5617\u8a66\u5c07\u4e00\u500b\u53d7\u63a7\u8f38\u5165\u8b8a\u70ba\u4e0d\u53d7\u63a7\u8f38\u5165\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u4f60\u6b63\u5728\u5617\u8a66\u5c07\u4e00\u500b\u53d7\u63a7\u8f38\u5165\u8b8a\u70ba\u4e0d\u53d7\u63a7\u8f38\u5165\uff1a<\/p>\n<pre class=\"brush: javascript\">\n<input type=\"text\" value={this.state.value} onChange={this.handleChange} \/>\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6587\u672c\u6846\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u56e0\u70ba\u5b83\u662f\u7531 this.state.value \u5c6c\u6027\u63a7\u5236\u7684\u3002\u5982\u679c\u4f60\u5617\u8a66\u5c07\u5b83\u8b8a\u70ba\u4e0d\u53d7\u63a7\u8f38\u5165\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: javascript\">\n<input type=\"text\" defaultValue=\"Hello World\" \/>\n<\/pre>\n<p>\u90a3\u9ebc React.js \u5c07\u6703\u767c\u51fa &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\u3002<\/p>\n<h2>\u5982\u4f55\u89e3\u6c7a &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\uff1f<\/h2>\n<p>\u8981\u89e3\u6c7a &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u7684\u8f38\u5165\u63a7\u4ef6\u59cb\u7d42\u4fdd\u6301\u53d7\u63a7\u72c0\u614b\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u4f60\u6709\u4e00\u500b\u6587\u672c\u6846\uff0c\u5b83\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u800c\u4e0d\u662f\u7531\u7528\u6236\u8f38\u5165\u7684\uff1a<\/p>\n<pre class=\"brush: javascript\">\n<input type=\"text\" value={this.state.value} onChange={this.handleChange} \/>\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6587\u672c\u6846\u7684\u503c\u662f\u7531 React.js \u63a7\u5236\u7684\uff0c\u56e0\u70ba\u5b83\u662f\u7531 this.state.value \u5c6c\u6027\u63a7\u5236\u7684\u3002\u7576\u7528\u6236\u8f38\u5165\u6587\u672c\u6846\u6642\uff0cReact.js \u5c07\u8abf\u7528 handleChange \u65b9\u6cd5\u66f4\u65b0 this.state.value \u5c6c\u6027\uff0c\u4ee5\u66f4\u65b0\u6587\u672c\u6846\u7684\u503c\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u8981\u89e3\u6c7a &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u7684\u8f38\u5165\u63a7\u4ef6\u59cb\u7d42\u4fdd\u6301\u53d7\u63a7\u72c0\u614b\uff0c\u800c\u4e0d\u662f\u5617\u8a66\u5c07\u5b83\u8b8a\u70ba\u4e0d\u53d7\u63a7\u8f38\u5165\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u89e3\u91cb\u4e86 React.js &#8220;Error: A component is changing a controlled input of type text to be uncontrolled&#8221; \u932f\u8aa4\u7684\u539f\u56e0\uff0c\u4ee5\u53ca\u5982\u4f55\u89e3\u6c7a\u5b83\u3002\u8981\u89e3\u6c7a\u9019\u500b\u932f\u8aa4\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u7684\u8f38\u5165\u63a7\u4ef6\u59cb\u7d42\u4fdd\u6301\u53d7\u63a7\u72c0\u614b\uff0c\u800c\u4e0d\u662f\u5617\u8a66\u5c07\u5b83\u8b8a\u70ba\u4e0d\u53d7\u63a7\u8f38\u5165\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u89e3\u6c7aReact.js\u4e2d\u7684&#8221;Error:Acomponentischangingacontrolledinputoftypetexttobeuncontrolled&#8221;\u932f\u8aa4\uff0c\u4e26\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528React.js\u4e2d\u7684methods()\u51fd\u6578\u4f86\u78ba\u4fdd\u8f38\u5165\u6846\u7684\u63a7\u5236\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-4729","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-1eh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4729","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=4729"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4729\/revisions"}],"predecessor-version":[{"id":4730,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4729\/revisions\/4730"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}