{"id":4754,"date":"2023-01-04T18:08:05","date_gmt":"2023-01-04T10:08:05","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4754"},"modified":"2023-01-04T18:08:05","modified_gmt":"2023-01-04T10:08:05","slug":"%e8%a7%a3%e6%b1%bareact-jserrorinvariantviolationelementtypeisinvalid%e7%9a%84%e6%8a%80%e5%b7%a7-2","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e8%a7%a3%e6%b1%bareact-jserrorinvariantviolationelementtypeisinvalid%e7%9a%84%e6%8a%80%e5%b7%a7-2\/","title":{"rendered":"\u89e3\u6c7aReact.js&#8221;Error:InvariantViolation:Elementtypeisinvalid&#8221;\u7684\u6280\u5de7"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.js, Error, Invariant Violation, Element type, built-in components, composite components, object\"><\/p>\n<p>React.js \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u754c\u9762\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: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class\/function (for composite components) but got: object.\u201d \u9019\u500b\u932f\u8aa4\u8868\u660e\uff0cReact.js \u7121\u6cd5\u8b58\u5225\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u5143\u7d20\u985e\u578b\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 React.js \u4e2d\uff0c\u5143\u7d20\u53ef\u4ee5\u662f\u5167\u7f6e\u7d44\u4ef6\uff08\u4f8b\u5982<\/p>\n<p>&lt;<\/p>\n<p>div>\uff09\u6216\u8907\u5408\u7d44\u4ef6\uff08\u4f8b\u5982 <MyComponent>\uff09\u3002\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u5143\u7d20\u4e0d\u662f\u5b57\u7b26\u4e32\uff08\u7528\u65bc\u5167\u7f6e\u7d44\u4ef6\uff09\u6216\u985e\/\u51fd\u6578\uff08\u7528\u65bc\u8907\u5408\u7d44\u4ef6\uff09\uff0c\u5247 React.js \u5c07\u7121\u6cd5\u8b58\u5225\u5b83\uff0c\u4e26\u4e14\u60a8\u5c07\u6536\u5230\u4e0a\u8ff0\u932f\u8aa4\u6d88\u606f\u3002<\/p>\n<p>\u8981\u89e3\u6c7a\u6b64\u554f\u984c\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u6b63\u5728\u4f7f\u7528\u6b63\u78ba\u7684\u5143\u7d20\u985e\u578b\u3002\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u5167\u7f6e\u7d44\u4ef6\uff0c\u5247\u60a8\u9700\u8981\u4f7f\u7528\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;div&gt;\n  ...\n&lt;\/div&gt;\n<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u8907\u5408\u7d44\u4ef6\uff0c\u5247\u60a8\u9700\u8981\u4f7f\u7528\u985e\/\u51fd\u6578\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;MyComponent&gt;\n  ...\n&lt;\/MyComponent&gt;\n<\/code><\/pre>\n<p>\u53e6\u5916\uff0c\u60a8\u9084\u9700\u8981\u78ba\u4fdd\u60a8\u6b63\u5728\u4f7f\u7528\u6b63\u78ba\u7684\u7d44\u4ef6\u540d\u7a31\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6b63\u5728\u4f7f\u7528\u8907\u5408\u7d44\u4ef6\uff0c\u5247\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u6b63\u5728\u4f7f\u7528\u6b63\u78ba\u7684\u7d44\u4ef6\u540d\u7a31\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;MyComponent&gt;\n  ...\n&lt;\/MyComponent&gt;\n<\/code><\/pre>\n<p>\u800c\u4e0d\u662f\uff1a<\/p>\n<pre><code class=\"line-numbers\">&lt;MyComp&gt;\n  ...\n&lt;\/MyComp&gt;\n<\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u6536\u5230\u201cError: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class\/function (for composite components) but got: object.\u201d \u932f\u8aa4\u6d88\u606f\uff0c\u5247\u60a8\u9700\u8981\u6aa2\u67e5\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u5143\u7d20\u985e\u578b\u662f\u5426\u6b63\u78ba\uff0c\u4ee5\u53ca\u60a8\u662f\u5426\u6b63\u5728\u4f7f\u7528\u6b63\u78ba\u7684\u7d44\u4ef6\u540d\u7a31\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aReact.js\u662f\u4e00\u500b\u975e\u5e38\u6d41\u884c\u7684JavaScript\u6846\u67b6\uff0c\u4f46\u662f\u5b83\u4e5f\u6703\u51fa\u73fe\u4e00\u4e9b\u932f\u8aa4\uff0c\u5176\u4e2d\u4e00\u500b\u5e38\u898b\u7684\u932f\u8aa4\u662f\u300cError:InvariantViolation:Elementtypeisinvalid\u300d\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7a\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-4754","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-1eG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4754","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=4754"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4754\/revisions"}],"predecessor-version":[{"id":4755,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4754\/revisions\/4755"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}