{"id":219002,"date":"2021-05-30T09:00:40","date_gmt":"2021-05-30T01:00:40","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=219002"},"modified":"2021-05-22T22:11:57","modified_gmt":"2021-05-22T14:11:57","slug":"upgrade-react17","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/upgrade-react17.html","title":{"rendered":"\u5347\u7ea7\u5230React 17\u4e4b\u524d\u5e94\u8be5\u77e5\u9053\u7684\u4e8b\u60c5"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u672c\u6587\u5c06\u8ba8\u8bbaJSX\u7684\u6539\u8fdb\uff0c\u5b83\u4eec\u80cc\u540e\u7684\u52a8\u673a\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u5f00\u53d1\u8005\u5728\u5347\u7ea7\u5230React 17\u4e4b\u524d\u5e94\u8be5\u77e5\u9053\u7684\u4e8b\u60c5\u3002\u4eca\u5929\u5206\u4eab\u7684\u5185\u5bb9\u662fReact 17\u4e2dJSX\u7684\u65b0\u7279\u6027\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u6b63\u6587<\/strong><\/div>\n \u672c\u6587\u4e3b\u8981\u4ecb\u7ecdReact 17\u4e2dJSX\u7684\u65b0\u7279\u6027\u4ee5\u53ca\u4f60\u4e3a\u4ec0\u4e48\u8981\u5173\u6ce8\u5b83\u3002<\/p>\n React 17\u7684\u53d1\u5e03\u662f\u72ec\u4e00\u65e0\u4e8c\u7684\u3002\u51e0\u4e4e\u6ca1\u6709\u4efb\u4f55\u4f60\u4f1a\u6ce8\u610f\u5230\u7684\u65b0\u529f\u80fd\u3002\u7136\u800c\uff0c\u4f60\u53ef\u4ee5\u627e\u5230\u51e0\u4e2a\u5bf9React\u6838\u5fc3\u5f71\u54cd\u5f88\u5927\u7684\u6539\u8fdb\u3002\u5728\u8fd9\u4e9b\u6539\u8fdb\u4e2d\uff0cJJSX\u7684\u53d8\u5316\u662f\u975e\u5e38\u660e\u663e\u7684\u3002<\/p>\n \u672c\u6587\u5c06\u8ba8\u8bbaJSX\u7684\u6539\u8fdb\uff0c\u5b83\u4eec\u80cc\u540e\u7684\u52a8\u673a\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u5f00\u53d1\u8005\u5728\u5347\u7ea7\u5230React 17\u4e4b\u524d\u5e94\u8be5\u77e5\u9053\u7684\u4e8b\u60c5\u3002<\/p>\n \u9996\u5148\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u4f60\u5c06\u4ece\u5916\u90e8\u4f53\u9a8c\u5230\u7684\u53d8\u5316\u3002<\/p>\n \u5bf9\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u53ef\u89c1\u7684\u53d8\u5316<\/strong><\/div>\n \u5bf9React 17\u7684\u80a4\u6d45\u7814\u7a76\u80af\u5b9a\u4f1a\u8ba9\u4f60\u5370\u8c61\u4e0d\u6df1\u3002\u771f\u6b63\u4ee4\u4eba\u5174\u594b\u7684\u4e1c\u897f\u4e0d\u662f\u65b0\u529f\u80fd\uff0c\u800c\u662f\u5728React\u7684\u7f16\u8bd1\u65b9\u5f0f\u3002<\/p>\n \u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e9b\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u4f7f\u7528\u65e7\u7248React\u7684\u7ec4\u4ef6\u4e2d\u7684JSX\u7684\u7f16\u8bd1\u4ee3\u7801\u3002<\/p>\n <\/p>\n \u4f60\u53ef\u80fd\u4f1a\u6ce8\u610f\u5230\uff0c\u7f16\u8bd1\u540e\u7684\u7248\u672c\u4f7f\u7528React.createElement\uff0c\u5176\u4e2dReact\u7684\u4f9d\u8d56\u6027\u5e94\u8be5\u5728\u8303\u56f4\u5185\u53ef\u7528\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f60\u9700\u8981\u5728\u6bcf\u4e2a\u7ec4\u4ef6\u4e2d\u9996\u5148\u5bfc\u5165React\u3002<\/p>\n \u73b0\u5728\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5b83\u5728React 17\u4e2d\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n \u6709\u4e86React 17\uff0c\u4f60\u5c31\u4e0d\u9700\u8981\u4e3aJSX\u5bfc\u5165React\u4e86\u3002<\/p>\n \u6211\u5e0c\u671b\u8fd9\u80fd\u63d0\u4f9b\u4e00\u4e2a\u7ebf\u7d22\uff0c\u5373\u7f16\u8bd1\u540e\u7684\u7248\u672c\u4e0d\u9700\u8981React\u7684\u5bfc\u5165\u3002<\/p>\n \u6b63\u5982\u4f60\u5728\u4e0b\u56fe\u4e2d\u770b\u5230\u7684\uff0cReact 17\u7f16\u8bd1\u5668\u4ecereact\/jsx-runtime\u5bfc\u5165\u4e86\u4e00\u4e2a\u65b0\u7684\u4f9d\u8d56\u9879\uff0c\u5b83\u5904\u7406JJSX\u8f6c\u6362\u3002<\/p>\n <\/p>\n \u56e0\u6b64\uff0c\u4f5c\u4e3a\u5f00\u53d1\u8005\uff0c\u4e00\u65e6\u4f60\u5347\u7ea7\u5230React 17\uff0c\u4f60\u53ef\u4ee5\u4ece\u4f60\u7684\u7ec4\u4ef6\u7684\u4ee3\u7801\u4e2d\u5220\u9664React\u5bfc\u5165\uff0c\u5982\u679c\u5b83\u53ea\u662f\u4e3a\u4e86JSX\u800c\u5b58\u5728\u3002<\/p>\n \u4f46\u8fd9\u662f\u552f\u4e00\u7684\u53d8\u5316\u5417\uff0c\u6709\u5173\u7cfb\u5417?<\/strong><\/div>\n \u6b63\u5982\u4f60\u5df2\u7ecf\u6ce8\u610f\u5230\u7684\uff0c\u4ece\u5916\u9762\u770b\u6548\u679c\u4f3c\u4e4e\u65e0\u5173\u7d27\u8981\u3002<\/p>\n \u91cd\u8981\u7684\u662f\u8981\u660e\u767d\uff0c\u5f53\u4f60\u7684\u4ee3\u7801\u5e93\u4e2d\u6709\u66f4\u591a\u7684React\u7ec4\u4ef6\u65f6\uff0c\u6574\u4f53\u6548\u679c\u4f1a\u663e\u73b0\u51fa\u6765<\/p>\n \u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u79cd\u5f71\u54cd\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u4e3a\u4ec0\u4e48\u53d6\u6d88\u4e0eReact.createElement\u7684\u4f9d\u8d56\u5173\u7cfb\u5bf9JSX\u5f88\u91cd\u8981\u3002<\/p>\n \u5220\u9664createElement\u7684\u597d\u5904<\/strong><\/div>\n \u9996\u5148\u505a\u4e2a\u603b\u7ed3\u7684\u8bdd\uff0c\u6709\u51e0\u4e2a\u70b9:<\/p>\n
\u51cf\u5c11\u6346\u7ed1\u6587\u4ef6\u7684\u5927\u5c0f<\/strong><\/span><\/div>\n \u9996\u5148\uff0c\u53ef\u4ee5\u60f3\u5230\u7684\u4e00\u70b9\u662f\uff1a\u51cf\u5c11\u6346\u7ed1\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n \u968f\u7740React\u5bfc\u5165\u7684\u5220\u9664\uff0c\u4f60\u7684\u7f16\u8bd1\u6346\u7ed1\u8f93\u51fa\u7684\u5927\u5c0f\u5c06\u53d8\u5f97\u7a0d\u5fae\u5c0f\u4e00\u4e9b\u3002\u6211\u5e0c\u671b\u8fd9\u4e00\u70b9\u53d8\u5f97\u5f88\u660e\u663e\uff0c\u56e0\u4e3a\u6211\u4eec\u9700\u8981\u5728\u7f16\u8bd1\u5668\u5c06\u5176\u66ff\u6362\u4e3aReact\u4e2d\u7684\u5b50\u6a21\u5757\u7684\u6bcf\u4e2a\u7ec4\u4ef6\u4e2d\u5220\u9664React\u5bfc\u5165\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n import {jsx as _jsx} from 'react\/jsx-runtime'; <\/pre>\n |