{"id":3030,"date":"2020-09-12T11:50:51","date_gmt":"2020-09-12T03:50:51","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=3030"},"modified":"2020-09-16T20:43:33","modified_gmt":"2020-09-16T12:43:33","slug":"%e5%bf%85%e9%a1%bb%e8%a6%81%e4%bc%9a%e7%9a%84-50-%e4%b8%aa-react-%e9%9d%a2%e8%af%95%e9%a2%98","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3030","title":{"rendered":"\u5fc5\u987b\u8981\u4f1a\u7684 50 \u4e2a React \u9762\u8bd5\u9898"},"content":{"rendered":"<p>\u5982\u679c\u4f60\u662f\u4e00\u4f4d\u6709\u62b1\u8d1f\u7684\u524d\u7aef\u7a0b\u5e8f\u5458\u5e76\u51c6\u5907\u9762\u8bd5\uff0c\u90a3\u4e48\u8fd9\u7bc7\u6587\u7ae0\u5f88\u9002\u5408\u4f60\u3002\u672c\u6587\u662f\u4f60\u5b66\u4e60\u548c\u9762\u8bd5 React \u6240\u9700\u77e5\u8bc6\u7684\u5b8c\u7f8e\u6307\u5357\u3002<\/p>\n<p>JavaScript \u5de5\u5177\u7f13\u6162\u800c\u7a33\u5b9a\u5730\u5728\u5e02\u573a\u4e2d\u624e\u6839\uff0c\u5bf9 React \u7684\u9700\u6c42\u5448\u6307\u6570\u7ea7\u589e\u957f\u3002\u9009\u62e9\u5408\u9002\u7684\u6280\u672f\u6765\u5f00\u53d1\u5e94\u7528\u6216\u7f51\u7ad9\u53d8\u5f97\u8d8a\u6765\u8d8a\u6709\u6311\u6218\u6027\u3002\u5176\u4e2d React \u88ab\u8ba4\u4e3a\u662f\u589e\u957f\u6700\u5feb\u7684 Javascript \u6846\u67b6\u3002<\/p>\n<p>\u622a\u81f3\u4eca\u5929\uff0cGithub \u4e0a\u7ea6\u67091,000\u540d\u8d21\u732e\u8005\u3002 Virtual DOM \u548c\u53ef\u91cd\u7528\u7ec4\u4ef6\u7b49\u72ec\u7279\u529f\u80fd\u5438\u5f15\u4e86\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u7684\u6ce8\u610f\u529b\u3002\u5c3d\u7ba1\u5b83\u53ea\u662f MVC\uff08\u6a21\u578b &#8211; \u89c6\u56fe &#8211; \u63a7\u5236\u5668\uff09\u4e2d\u201c\u89c6\u56fe\u201d\u7684\u5e93\uff0c\u4f46\u5b83\u5bf9 Angular\uff0cMeteor\uff0cVue \u7b49\u5168\u9762\u7684\u6846\u67b6\u4e5f\u6784\u6210\u4e86\u5f3a\u529b\u7684\u6311\u6218\u3002\u4e0b\u56fe\u4e3a\u6d41\u884c\u7684 JS \u6846\u67b6\u7684\u8d8b\u52bf\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114527.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3031\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114527.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114527\" width=\"1169\" height=\"439\" \/><\/a><\/p>\n<p><em>JS \u6846\u67b6\u7684\u8d8b\u52bf<\/em><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>React \u9762\u8bd5\u9898<\/strong><\/h2>\n<p>\u4ee5\u4e0b\u662f\u9762\u8bd5\u5b98\u6700\u6709\u53ef\u80fd\u95ee\u5230\u7684 <strong>50 \u4e2a React \u9762\u8bd5\u9898\u548c\u7b54\u6848<\/strong>\u3002\u4e3a\u65b9\u4fbf\u4f60\u5b66\u4e60\uff0c\u6211\u5bf9\u5b83\u4eec\u8fdb\u884c\u4e86\u5206\u7c7b\uff1a<\/p>\n<ul>\n<li>\u57fa\u672c\u77e5\u8bc6<\/li>\n<li>React \u7ec4\u4ef6<\/li>\n<li>React Redux<\/li>\n<li>React \u8def\u7531<\/li>\n<\/ul>\n<h2><strong>\u57fa\u672c\u77e5\u8bc6<\/strong><\/h2>\n<h3><strong>1. \u533a\u5206Real DOM\u548cVirtual DOM<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>Real DOM<\/strong><\/th>\n<th><strong>Virtual DOM<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. \u66f4\u65b0\u7f13\u6162\u3002<\/td>\n<td>1. \u66f4\u65b0\u66f4\u5feb\u3002<\/td>\n<\/tr>\n<tr>\n<td>2. \u53ef\u4ee5\u76f4\u63a5\u66f4\u65b0 HTML\u3002<\/td>\n<td>2. \u65e0\u6cd5\u76f4\u63a5\u66f4\u65b0 HTML\u3002<\/td>\n<\/tr>\n<tr>\n<td>3. \u5982\u679c\u5143\u7d20\u66f4\u65b0\uff0c\u5219\u521b\u5efa\u65b0DOM\u3002<\/td>\n<td>3. \u5982\u679c\u5143\u7d20\u66f4\u65b0\uff0c\u5219\u66f4\u65b0 JSX \u3002<\/td>\n<\/tr>\n<tr>\n<td>4. DOM\u64cd\u4f5c\u4ee3\u4ef7\u5f88\u9ad8\u3002<\/td>\n<td>4. DOM \u64cd\u4f5c\u975e\u5e38\u7b80\u5355\u3002<\/td>\n<\/tr>\n<tr>\n<td>5. \u6d88\u8017\u7684\u5185\u5b58\u8f83\u591a\u3002<\/td>\n<td>5. \u5f88\u5c11\u7684\u5185\u5b58\u6d88\u8017\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><strong>2. \u4ec0\u4e48\u662fReact\uff1f<\/strong><\/h3>\n<ul>\n<li>React \u662f Facebook \u5728 2011 \u5e74\u5f00\u53d1\u7684\u524d\u7aef JavaScript \u5e93\u3002<\/li>\n<li>\u5b83\u9075\u5faa\u57fa\u4e8e\u7ec4\u4ef6\u7684\u65b9\u6cd5\uff0c\u6709\u52a9\u4e8e\u6784\u5efa\u53ef\u91cd\u7528\u7684UI\u7ec4\u4ef6\u3002<\/li>\n<li>\u5b83\u7528\u4e8e\u5f00\u53d1\u590d\u6742\u548c\u4ea4\u4e92\u5f0f\u7684 Web \u548c\u79fb\u52a8 UI\u3002<\/li>\n<li>\u5c3d\u7ba1\u5b83\u4ec5\u5728 2015 \u5e74\u5f00\u6e90\uff0c\u4f46\u6709\u4e00\u4e2a\u5f88\u5927\u7684\u652f\u6301\u793e\u533a\u3002<\/li>\n<\/ul>\n<h3><strong>3. React\u6709\u4ec0\u4e48\u7279\u70b9\uff1f<\/strong><\/h3>\n<p>React\u7684\u4e3b\u8981\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5b83\u4f7f\u7528<strong>\u865a\u62dfDOM <\/strong>\u800c\u4e0d\u662f\u771f\u6b63\u7684DOM\u3002<\/li>\n<li>\u5b83\u53ef\u4ee5\u7528<strong>\u670d\u52a1\u5668\u7aef\u6e32\u67d3<\/strong>\u3002<\/li>\n<li>\u5b83\u9075\u5faa<strong>\u5355\u5411\u6570\u636e\u6d41<\/strong>\u6216\u6570\u636e\u7ed1\u5b9a\u3002<\/li>\n<\/ol>\n<h3><strong>4. \u5217\u51faReact\u7684\u4e00\u4e9b\u4e3b\u8981\u4f18\u70b9\u3002<\/strong><\/h3>\n<p>React\u7684\u4e00\u4e9b\u4e3b\u8981\u4f18\u70b9\u662f\uff1a<\/p>\n<ol>\n<li>\u5b83\u63d0\u9ad8\u4e86\u5e94\u7528\u7684\u6027\u80fd<\/li>\n<li>\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7aef\u4f7f\u7528<\/li>\n<li>\u7531\u4e8e JSX\uff0c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u5f88\u597d<\/li>\n<li>React \u5f88\u5bb9\u6613\u4e0e Meteor\uff0cAngular \u7b49\u5176\u4ed6\u6846\u67b6\u96c6\u6210<\/li>\n<li>\u4f7f\u7528React\uff0c\u7f16\u5199UI\u6d4b\u8bd5\u7528\u4f8b\u53d8\u5f97\u975e\u5e38\u5bb9\u6613<\/li>\n<\/ol>\n<h3><strong>5. React\u6709\u54ea\u4e9b\u9650\u5236\uff1f<\/strong><\/h3>\n<p>React\u7684\u9650\u5236\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>React \u53ea\u662f\u4e00\u4e2a\u5e93\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u6846\u67b6<\/li>\n<li>\u5b83\u7684\u5e93\u975e\u5e38\u5e9e\u5927\uff0c\u9700\u8981\u65f6\u95f4\u6765\u7406\u89e3<\/li>\n<li>\u65b0\u624b\u7a0b\u5e8f\u5458\u53ef\u80fd\u5f88\u96be\u7406\u89e3<\/li>\n<li>\u7f16\u7801\u53d8\u5f97\u590d\u6742\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528\u5185\u8054\u6a21\u677f\u548c JSX<\/li>\n<\/ol>\n<h3><strong>6. \u4ec0\u4e48\u662fJSX\uff1f<\/strong><\/h3>\n<p>JSX \u662fJ avaScript XML \u7684\u7b80\u5199\u3002\u662f React \u4f7f\u7528\u7684\u4e00\u79cd\u6587\u4ef6\uff0c\u5b83\u5229\u7528 JavaScript \u7684\u8868\u73b0\u529b\u548c\u7c7b\u4f3c HTML \u7684\u6a21\u677f\u8bed\u6cd5\u3002\u8fd9\u4f7f\u5f97 HTML \u6587\u4ef6\u975e\u5e38\u5bb9\u6613\u7406\u89e3\u3002\u6b64\u6587\u4ef6\u80fd\u4f7f\u5e94\u7528\u975e\u5e38\u53ef\u9760\uff0c\u5e76\u80fd\u591f\u63d0\u9ad8\u5176\u6027\u80fd\u3002\u4e0b\u9762\u662fJSX\u7684\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code>render(){\r\n    return(        \r\n        &lt;div&gt;\r\n            &lt;h1&gt; Hello World from Edureka!!&lt;\/h1&gt;\r\n        &lt;\/div&gt;\r\n    );\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>7. \u4f60\u4e86\u89e3 Virtual DOM \u5417\uff1f\u89e3\u91ca\u4e00\u4e0b\u5b83\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/strong><\/h3>\n<p>Virtual DOM \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 JavaScript \u5bf9\u8c61\uff0c\u5b83\u6700\u521d\u53ea\u662f real DOM \u7684\u526f\u672c\u3002\u5b83\u662f\u4e00\u4e2a\u8282\u70b9\u6811\uff0c\u5b83\u5c06\u5143\u7d20\u3001\u5b83\u4eec\u7684\u5c5e\u6027\u548c\u5185\u5bb9\u4f5c\u4e3a\u5bf9\u8c61\u53ca\u5176\u5c5e\u6027\u3002 React \u7684\u6e32\u67d3\u51fd\u6570\u4ece React \u7ec4\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u8282\u70b9\u6811\u3002\u7136\u540e\u5b83\u54cd\u5e94\u6570\u636e\u6a21\u578b\u4e2d\u7684\u53d8\u5316\u6765\u66f4\u65b0\u8be5\u6811\uff0c\u8be5\u53d8\u5316\u662f\u7531\u7528\u6237\u6216\u7cfb\u7edf\u5b8c\u6210\u7684\u5404\u79cd\u52a8\u4f5c\u5f15\u8d77\u7684\u3002<\/p>\n<p>Virtual DOM \u5de5\u4f5c\u8fc7\u7a0b\u6709\u4e09\u4e2a\u7b80\u5355\u7684\u6b65\u9aa4\u3002<\/p>\n<ol>\n<li>\u6bcf\u5f53\u5e95\u5c42\u6570\u636e\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u6574\u4e2a UI \u90fd\u5c06\u5728 Virtual DOM \u63cf\u8ff0\u4e2d\u91cd\u65b0\u6e32\u67d3\u3002<img decoding=\"async\" src=\"https:\/\/user-gold-cdn.xitu.io\/2019\/3\/25\/169b42c3abe78a05?imageView2\/0\/w\/1280\/h\/960\/format\/webp\/ignore-error\/1\" alt=\"Virtual DOM 1\" \/><\/li>\n<li>\u7136\u540e\u8ba1\u7b97\u4e4b\u524d DOM \u8868\u793a\u4e0e\u65b0\u8868\u793a\u7684\u4e4b\u95f4\u7684\u5dee\u5f02\u3002<img decoding=\"async\" src=\"https:\/\/user-gold-cdn.xitu.io\/2019\/3\/25\/169b42c3b5c6759a?imageView2\/0\/w\/1280\/h\/960\/format\/webp\/ignore-error\/1\" alt=\"Virtual DOM 2\" \/><\/li>\n<li>\u5b8c\u6210\u8ba1\u7b97\u540e\uff0c\u5c06\u53ea\u7528\u5b9e\u9645\u66f4\u6539\u7684\u5185\u5bb9\u66f4\u65b0 real DOM\u3002<img decoding=\"async\" src=\"https:\/\/user-gold-cdn.xitu.io\/2019\/3\/25\/169b42c3b5163360?imageView2\/0\/w\/1280\/h\/960\/format\/webp\/ignore-error\/1\" alt=\"Virtual DOM 3\" \/><\/li>\n<\/ol>\n<h3><strong>8. \u4e3a\u4ec0\u4e48\u6d4f\u89c8\u5668\u65e0\u6cd5\u8bfb\u53d6JSX\uff1f<\/strong><\/h3>\n<p>\u6d4f\u89c8\u5668\u53ea\u80fd\u5904\u7406 JavaScript \u5bf9\u8c61\uff0c\u800c\u4e0d\u80fd\u8bfb\u53d6\u5e38\u89c4 JavaScript \u5bf9\u8c61\u4e2d\u7684 JSX\u3002\u6240\u4ee5\u4e3a\u4e86\u4f7f\u6d4f\u89c8\u5668\u80fd\u591f\u8bfb\u53d6 JSX\uff0c\u9996\u5148\uff0c\u9700\u8981\u7528\u50cf Babel \u8fd9\u6837\u7684 JSX \u8f6c\u6362\u5668\u5c06 JSX \u6587\u4ef6\u8f6c\u6362\u4e3a JavaScript \u5bf9\u8c61\uff0c\u7136\u540e\u518d\u5c06\u5176\u4f20\u7ed9\u6d4f\u89c8\u5668\u3002<\/p>\n<h3><strong>9. \u4e0e ES5 \u76f8\u6bd4\uff0cReact \u7684 ES6 \u8bed\u6cd5\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><\/h3>\n<p>\u4ee5\u4e0b\u8bed\u6cd5\u662f ES5 \u4e0e ES6 \u4e2d\u7684\u533a\u522b\uff1a<\/p>\n<ol>\n<li>require \u4e0e import<\/li>\n<\/ol>\n<pre><code>\/\/ ES5\r\nvar React = require('react');\r\n \r\n\/\/ ES6\r\nimport React from 'react';\r\n\r\n<\/code><\/pre>\n<ol>\n<li>export \u4e0e exports<\/li>\n<\/ol>\n<pre><code>\/\/ ES5\r\nmodule.exports = Component;\r\n \r\n\/\/ ES6\r\nexport default Component;\r\n\r\n<\/code><\/pre>\n<ol>\n<li>component \u548c function<\/li>\n<\/ol>\n<pre><code>\/\/ ES5\r\nvar MyComponent = React.createClass({\r\n    render: function() {\r\n        return\r\n\t\t\t&lt;h3&gt;Hello Edureka!&lt;\/h3&gt;;\r\n    }\r\n});\r\n \r\n\/\/ ES6\r\nclass MyComponent extends React.Component {\r\n    render() {\r\n        return\r\n\t\t\t&lt;h3&gt;Hello Edureka!&lt;\/h3&gt;;\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<ol>\n<li>props<\/li>\n<\/ol>\n<pre><code>\/\/ ES5\r\nvar App = React.createClass({\r\n    propTypes: { name: React.PropTypes.string },\r\n    render: function() {\r\n        return\r\n\t\t\t&lt;h3&gt;Hello, {this.props.name}!&lt;\/h3&gt;;\r\n    }\r\n});\r\n\r\n\/\/ ES6\r\nclass App extends React.Component {\r\n    render() {\r\n        return\r\n\t\t\t&lt;h3&gt;Hello, {this.props.name}!&lt;\/h3&gt;;\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<ol>\n<li>state<\/li>\n<\/ol>\n<pre><code>\/\/ ES5\r\nvar App = React.createClass({\r\n    getInitialState: function() {\r\n        return { name: 'world' };\r\n    },\r\n    render: function() {\r\n        return\r\n\t        &lt;h3&gt;Hello, {this.state.name}!&lt;\/h3&gt;;\r\n    }\r\n});\r\n\r\n\/\/ ES6\r\nclass App extends React.Component {\r\n    constructor() {\r\n        super();\r\n        this.state = { name: 'world' };\r\n    }\r\n    render() {\r\n        return\r\n\t        &lt;h3&gt;Hello, {this.state.name}!&lt;\/h3&gt;;\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>10. React\u4e0eAngular\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>\u4e3b\u9898<\/strong><\/th>\n<th><strong>React<\/strong><\/th>\n<th><strong>Angular<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><em>1. \u4f53\u7cfb\u7ed3\u6784<\/em><\/td>\n<td>\u53ea\u6709 MVC \u4e2d\u7684 View<\/td>\n<td>\u5b8c\u6574\u7684 MVC<\/td>\n<\/tr>\n<tr>\n<td><em>2. \u6e32\u67d3<\/em><\/td>\n<td>\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u7aef\u6e32\u67d3<\/td>\n<td>\u5ba2\u6237\u7aef\u6e32\u67d3<\/td>\n<\/tr>\n<tr>\n<td><em>3. DOM<\/em><\/td>\n<td>\u4f7f\u7528 virtual DOM<\/td>\n<td>\u4f7f\u7528 real DOM<\/td>\n<\/tr>\n<tr>\n<td><em>4. \u6570\u636e\u7ed1\u5b9a<\/em><\/td>\n<td>\u5355\u5411\u6570\u636e\u7ed1\u5b9a<\/td>\n<td>\u53cc\u5411\u6570\u636e\u7ed1\u5b9a<\/td>\n<\/tr>\n<tr>\n<td><em>5. \u8c03\u8bd5<\/em><\/td>\n<td>\u7f16\u8bd1\u65f6\u8c03\u8bd5<\/td>\n<td>\u8fd0\u884c\u65f6\u8c03\u8bd5<\/td>\n<\/tr>\n<tr>\n<td><em>6. \u4f5c\u8005<\/em><\/td>\n<td>Facebook<\/td>\n<td>Google<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2><strong>React \u7ec4\u4ef6<\/strong><\/h2>\n<h3><strong>11. \u4f60\u7406\u89e3\u201c\u5728React\u4e2d\uff0c\u4e00\u5207\u90fd\u662f\u7ec4\u4ef6\u201d\u8fd9\u53e5\u8bdd\u3002<\/strong><\/h3>\n<p>\u7ec4\u4ef6\u662f React \u5e94\u7528 UI \u7684\u6784\u5efa\u5757\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u5c06\u6574\u4e2a UI \u5206\u6210\u5c0f\u7684\u72ec\u7acb\u5e76\u53ef\u91cd\u7528\u7684\u90e8\u5206\u3002\u6bcf\u4e2a\u7ec4\u4ef6\u5f7c\u6b64\u72ec\u7acb\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd UI \u7684\u5176\u4f59\u90e8\u5206\u3002<\/p>\n<h3><strong>12. \u89e3\u91ca React \u4e2d render() \u7684\u76ee\u7684\u3002<\/strong><\/h3>\n<p>\u6bcf\u4e2aReact\u7ec4\u4ef6\u5f3a\u5236\u8981\u6c42\u5fc5\u987b\u6709\u4e00\u4e2a <strong>render()<\/strong>\u3002\u5b83\u8fd4\u56de\u4e00\u4e2a React \u5143\u7d20\uff0c\u662f\u539f\u751f DOM \u7ec4\u4ef6\u7684\u8868\u793a\u3002\u5982\u679c\u9700\u8981\u6e32\u67d3\u591a\u4e2a HTML \u5143\u7d20\uff0c\u5219\u5fc5\u987b\u5c06\u5b83\u4eec\u7ec4\u5408\u5728\u4e00\u4e2a\u5c01\u95ed\u6807\u8bb0\u5185\uff0c\u4f8b\u5982 <code>\u3001<\/code>\u3001&#8220; \u7b49\u3002\u6b64\u51fd\u6570\u5fc5\u987b\u4fdd\u6301\u7eaf\u51c0\uff0c\u5373\u5fc5\u987b\u6bcf\u6b21\u8c03\u7528\u65f6\u90fd\u8fd4\u56de\u76f8\u540c\u7684\u7ed3\u679c\u3002<\/p>\n<h3><strong>13. \u5982\u4f55\u5c06\u4e24\u4e2a\u6216\u591a\u4e2a\u7ec4\u4ef6\u5d4c\u5165\u5230\u4e00\u4e2a\u7ec4\u4ef6\u4e2d\uff1f<\/strong><\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5c06\u7ec4\u4ef6\u5d4c\u5165\u5230\u4e00\u4e2a\u7ec4\u4ef6\u4e2d\uff1a<\/p>\n<pre><code>class MyComponent extends React.Component{\r\n    render(){\r\n        return(          \r\n\t\t\t&lt;div&gt;\r\n            \t&lt;h1&gt;Hello&lt;\/h1&gt;\r\n                &lt;Header\/&gt;\r\n            &lt;\/div&gt;\r\n        );\r\n    }\r\n}\r\nclass Header extends React.Component{\r\n    render(){\r\n        return\r\n\t\t\t&lt;h1&gt;Header Component&lt;\/h1&gt;   \r\n   };\r\n}\r\nReactDOM.render(\r\n    &lt;MyComponent\/&gt;, document.getElementById('content')\r\n);\r\n\r\n<\/code><\/pre>\n<h3><strong>14. \u4ec0\u4e48\u662f Props?<\/strong><\/h3>\n<p>Props \u662f React \u4e2d\u5c5e\u6027\u7684\u7b80\u5199\u3002\u5b83\u4eec\u662f\u53ea\u8bfb\u7ec4\u4ef6\uff0c\u5fc5\u987b\u4fdd\u6301\u7eaf\uff0c\u5373\u4e0d\u53ef\u53d8\u3002\u5b83\u4eec\u603b\u662f\u5728\u6574\u4e2a\u5e94\u7528\u4e2d\u4ece\u7236\u7ec4\u4ef6\u4f20\u9012\u5230\u5b50\u7ec4\u4ef6\u3002\u5b50\u7ec4\u4ef6\u6c38\u8fdc\u4e0d\u80fd\u5c06 prop \u9001\u56de\u7236\u7ec4\u4ef6\u3002\u8fd9\u6709\u52a9\u4e8e\u7ef4\u62a4\u5355\u5411\u6570\u636e\u6d41\uff0c\u901a\u5e38\u7528\u4e8e\u5448\u73b0\u52a8\u6001\u751f\u6210\u7684\u6570\u636e\u3002<\/p>\n<h3><strong>15. React\u4e2d\u7684\u72b6\u6001\u662f\u4ec0\u4e48\uff1f\u5b83\u662f\u5982\u4f55\u4f7f\u7528\u7684\uff1f<\/strong><\/h3>\n<p>\u72b6\u6001\u662f React \u7ec4\u4ef6\u7684\u6838\u5fc3\uff0c\u662f\u6570\u636e\u7684\u6765\u6e90\uff0c\u5fc5\u987b\u5c3d\u53ef\u80fd\u7b80\u5355\u3002\u57fa\u672c\u4e0a\u72b6\u6001\u662f\u786e\u5b9a\u7ec4\u4ef6\u5448\u73b0\u548c\u884c\u4e3a\u7684\u5bf9\u8c61\u3002\u4e0eprops \u4e0d\u540c\uff0c\u5b83\u4eec\u662f\u53ef\u53d8\u7684\uff0c\u5e76\u521b\u5efa\u52a8\u6001\u548c\u4ea4\u4e92\u5f0f\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7 <code>this.state()<\/code> \u8bbf\u95ee\u5b83\u4eec\u3002<\/p>\n<h3><strong>16. \u533a\u5206\u72b6\u6001\u548c props<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>\u6761\u4ef6<\/strong><\/th>\n<th><strong>State<\/strong><\/th>\n<th><strong>Props<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. \u4ece\u7236\u7ec4\u4ef6\u4e2d\u63a5\u6536\u521d\u59cb\u503c<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>2. \u7236\u7ec4\u4ef6\u53ef\u4ee5\u6539\u53d8\u503c<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>3. \u5728\u7ec4\u4ef6\u4e2d\u8bbe\u7f6e\u9ed8\u8ba4\u503c<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>4. \u5728\u7ec4\u4ef6\u7684\u5185\u90e8\u53d8\u5316<\/td>\n<td>Yes<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>5. \u8bbe\u7f6e\u5b50\u7ec4\u4ef6\u7684\u521d\u59cb\u503c<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>6. \u5728\u5b50\u7ec4\u4ef6\u7684\u5185\u90e8\u66f4\u6539<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><strong>17. \u5982\u4f55\u66f4\u65b0\u7ec4\u4ef6\u7684\u72b6\u6001\uff1f<\/strong><\/h3>\n<p>\u53ef\u4ee5\u7528 <code>this.setState()<\/code>\u66f4\u65b0\u7ec4\u4ef6\u7684\u72b6\u6001\u3002<\/p>\n<pre><code>class MyComponent extends React.Component {\r\n    constructor() {\r\n        super();\r\n        this.state = {\r\n            name: 'Maxx',\r\n            id: '101'\r\n        }\r\n    }\r\n    render()\r\n        {\r\n            setTimeout(()=&gt;{this.setState({name:'Jaeha', id:'222'})},2000)\r\n            return (              \r\n\t\t\t\t&lt;div&gt;\r\n                \t&lt;h1&gt;Hello {this.state.name}&lt;\/h1&gt;\r\n\t\t\t\t\t&lt;h2&gt;Your Id is {this.state.id}&lt;\/h2&gt;\r\n                &lt;\/div&gt;\r\n            );\r\n        }\r\n    }\r\nReactDOM.render(\r\n    &lt;MyComponent\/&gt;, document.getElementById('content')\r\n);\r\n\r\n<\/code><\/pre>\n<h3><strong>18. React \u4e2d\u7684\u7bad\u5934\u51fd\u6570\u662f\u4ec0\u4e48\uff1f\u600e\u4e48\u7528\uff1f<\/strong><\/h3>\n<p>\u7bad\u5934\u51fd\u6570\uff08<strong>=&gt;<\/strong>\uff09\u662f\u7528\u4e8e\u7f16\u5199\u51fd\u6570\u8868\u8fbe\u5f0f\u7684\u7b80\u77ed\u8bed\u6cd5\u3002\u8fd9\u4e9b\u51fd\u6570\u5141\u8bb8\u6b63\u786e\u7ed1\u5b9a\u7ec4\u4ef6\u7684\u4e0a\u4e0b\u6587\uff0c\u56e0\u4e3a\u5728 ES6 \u4e2d\u9ed8\u8ba4\u4e0b\u4e0d\u80fd\u4f7f\u7528\u81ea\u52a8\u7ed1\u5b9a\u3002\u4f7f\u7528\u9ad8\u9636\u51fd\u6570\u65f6\uff0c\u7bad\u5934\u51fd\u6570\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>\/\/General way\r\nrender() {    \r\n    return(\r\n        &lt;MyInput onChange = {this.handleChange.bind(this) } \/&gt;\r\n    );\r\n}\r\n\/\/With Arrow Function\r\nrender() {  \r\n    return(\r\n        &lt;MyInput onChange = { (e)=&gt;this.handleOnChange(e) } \/&gt;\r\n    );\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>19. \u533a\u5206\u6709\u72b6\u6001\u548c\u65e0\u72b6\u6001\u7ec4\u4ef6\u3002<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>\u6709\u72b6\u6001\u7ec4\u4ef6<\/strong><\/th>\n<th><strong>\u65e0\u72b6\u6001\u7ec4\u4ef6<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. \u5728\u5185\u5b58\u4e2d\u5b58\u50a8\u6709\u5173\u7ec4\u4ef6\u72b6\u6001\u53d8\u5316\u7684\u4fe1\u606f<\/td>\n<td>1. \u8ba1\u7b97\u7ec4\u4ef6\u7684\u5185\u90e8\u7684\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>2. \u6709\u6743\u6539\u53d8\u72b6\u6001<\/td>\n<td>2. \u65e0\u6743\u6539\u53d8\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>3. \u5305\u542b\u8fc7\u53bb\u3001\u73b0\u5728\u548c\u672a\u6765\u53ef\u80fd\u7684\u72b6\u6001\u53d8\u5316\u60c5\u51b5<\/td>\n<td>3. \u4e0d\u5305\u542b\u8fc7\u53bb\uff0c\u73b0\u5728\u548c\u672a\u6765\u53ef\u80fd\u53d1\u751f\u7684\u72b6\u6001\u53d8\u5316\u60c5\u51b5<\/td>\n<\/tr>\n<tr>\n<td>4. \u63a5\u53d7\u65e0\u72b6\u6001\u7ec4\u4ef6\u72b6\u6001\u53d8\u5316\u8981\u6c42\u7684\u901a\u77e5\uff0c\u7136\u540e\u5c06 props \u53d1\u9001\u7ed9\u4ed6\u4eec\u3002<\/td>\n<td>4.\u4ece\u6709\u72b6\u6001\u7ec4\u4ef6\u63a5\u6536 props \u5e76\u5c06\u5176\u89c6\u4e3a\u56de\u8c03\u51fd\u6570\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><strong>20. React\u7ec4\u4ef6\u751f\u547d\u5468\u671f\u7684\u9636\u6bb5\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>React \u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\u6709\u4e09\u4e2a\u4e0d\u540c\u7684\u9636\u6bb5\uff1a<\/p>\n<ol>\n<li><em>\u521d\u59cb\u6e32\u67d3\u9636\u6bb5\uff1a<\/em>\u8fd9\u662f\u7ec4\u4ef6\u5373\u5c06\u5f00\u59cb\u5176\u751f\u547d\u4e4b\u65c5\u5e76\u8fdb\u5165 DOM \u7684\u9636\u6bb5\u3002<\/li>\n<li><em>\u66f4\u65b0\u9636\u6bb5\uff1a<\/em>\u4e00\u65e6\u7ec4\u4ef6\u88ab\u6dfb\u52a0\u5230 DOM\uff0c\u5b83\u53ea\u6709\u5728 prop \u6216\u72b6\u6001\u53d1\u751f\u53d8\u5316\u65f6\u624d\u53ef\u80fd\u66f4\u65b0\u548c\u91cd\u65b0\u6e32\u67d3\u3002\u8fd9\u4e9b\u53ea\u53d1\u751f\u5728\u8fd9\u4e2a\u9636\u6bb5\u3002<\/li>\n<li><em>\u5378\u8f7d\u9636\u6bb5\uff1a<\/em>\u8fd9\u662f\u7ec4\u4ef6\u751f\u547d\u5468\u671f\u7684\u6700\u540e\u9636\u6bb5\uff0c\u7ec4\u4ef6\u88ab\u9500\u6bc1\u5e76\u4ece DOM \u4e2d\u5220\u9664\u3002<\/li>\n<\/ol>\n<h3><strong>21. \u8be6\u7ec6\u89e3\u91ca React \u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f\u65b9\u6cd5\u3002<\/strong><\/h3>\n<p>\u4e00\u4e9b\u6700\u91cd\u8981\u7684\u751f\u547d\u5468\u671f\u65b9\u6cd5\u662f\uff1a<\/p>\n<ol>\n<li><strong><em>componentWillMount<\/em><\/strong><strong>()<\/strong> \u2013 \u5728\u6e32\u67d3\u4e4b\u524d\u6267\u884c\uff0c\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7aef\u90fd\u4f1a\u6267\u884c\u3002<\/li>\n<li><strong><em>componentDidMount<\/em><\/strong><strong>()<\/strong> \u2013 \u4ec5\u5728\u7b2c\u4e00\u6b21\u6e32\u67d3\u540e\u5728\u5ba2\u6237\u7aef\u6267\u884c\u3002<\/li>\n<li><strong><em>componentWillReceiveProps<\/em><\/strong><strong>()<\/strong> \u2013 \u5f53\u4ece\u7236\u7c7b\u63a5\u6536\u5230 props \u5e76\u4e14\u5728\u8c03\u7528\u53e6\u4e00\u4e2a\u6e32\u67d3\u5668\u4e4b\u524d\u8c03\u7528\u3002<\/li>\n<li><strong><em>shouldComponentUpdate<\/em><\/strong><strong>()<\/strong> \u2013 \u6839\u636e\u7279\u5b9a\u6761\u4ef6\u8fd4\u56de true \u6216 false\u3002\u5982\u679c\u4f60\u5e0c\u671b\u66f4\u65b0\u7ec4\u4ef6\uff0c\u8bf7\u8fd4\u56de<strong>true<\/strong> \u5426\u5219\u8fd4\u56de <strong>false<\/strong>\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u8fd4\u56de false\u3002<\/li>\n<li><strong><em>componentWillUpdate<\/em><\/strong><strong>()<\/strong> \u2013 \u5728 DOM \u4e2d\u8fdb\u884c\u6e32\u67d3\u4e4b\u524d\u8c03\u7528\u3002<\/li>\n<li><strong><em>componentDidUpdate<\/em><\/strong><strong>()<\/strong> \u2013 \u5728\u6e32\u67d3\u53d1\u751f\u540e\u7acb\u5373\u8c03\u7528\u3002<\/li>\n<li><strong><em>componentWillUnmount<\/em><\/strong><strong>()<\/strong> \u2013 \u4ece DOM \u5378\u8f7d\u7ec4\u4ef6\u540e\u8c03\u7528\u3002\u7528\u4e8e\u6e05\u7406\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<\/ol>\n<h3><strong>22. React\u4e2d\u7684\u4e8b\u4ef6\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>\u5728 React \u4e2d\uff0c\u4e8b\u4ef6\u662f\u5bf9\u9f20\u6807\u60ac\u505c\u3001\u9f20\u6807\u5355\u51fb\u3001\u6309\u952e\u7b49\u7279\u5b9a\u64cd\u4f5c\u7684\u89e6\u53d1\u53cd\u5e94\u3002\u5904\u7406\u8fd9\u4e9b\u4e8b\u4ef6\u7c7b\u4f3c\u4e8e\u5904\u7406 DOM \u5143\u7d20\u4e2d\u7684\u4e8b\u4ef6\u3002\u4f46\u662f\u6709\u4e00\u4e9b\u8bed\u6cd5\u5dee\u5f02\uff0c\u5982\uff1a<\/p>\n<ol>\n<li>\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5\u5bf9\u4e8b\u4ef6\u547d\u540d\u800c\u4e0d\u662f\u4ec5\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u3002<\/li>\n<li>\u4e8b\u4ef6\u4f5c\u4e3a\u51fd\u6570\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\u4f20\u9012\u3002<\/li>\n<\/ol>\n<p>\u4e8b\u4ef6\u53c2\u6570\u91cd\u5305\u542b\u4e00\u7ec4\u7279\u5b9a\u4e8e\u4e8b\u4ef6\u7684\u5c5e\u6027\u3002\u6bcf\u4e2a\u4e8b\u4ef6\u7c7b\u578b\u90fd\u5305\u542b\u81ea\u5df1\u7684\u5c5e\u6027\u548c\u884c\u4e3a\uff0c\u53ea\u80fd\u901a\u8fc7\u5176\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u8bbf\u95ee\u3002<\/p>\n<h3><strong>23. \u5982\u4f55\u5728React\u4e2d\u521b\u5efa\u4e00\u4e2a\u4e8b\u4ef6\uff1f<\/strong><\/h3>\n<pre><code>class Display extends React.Component({    \r\n    show(evt) {\r\n        \/\/ code   \r\n    },   \r\n    render() {      \r\n        \/\/ Render the div with an onClick prop (value is a function)        \r\n        return (            \r\n            &lt;div onClick={this.show}&gt;Click Me!&lt;\/div&gt;\r\n        );    \r\n    }\r\n});\r\n\r\n<\/code><\/pre>\n<h3><strong>24. React\u4e2d\u7684\u5408\u6210\u4e8b\u4ef6\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>\u5408\u6210\u4e8b\u4ef6\u662f\u56f4\u7ed5\u6d4f\u89c8\u5668\u539f\u751f\u4e8b\u4ef6\u5145\u5f53\u8de8\u6d4f\u89c8\u5668\u5305\u88c5\u5668\u7684\u5bf9\u8c61\u3002\u5b83\u4eec\u5c06\u4e0d\u540c\u6d4f\u89c8\u5668\u7684\u884c\u4e3a\u5408\u5e76\u4e3a\u4e00\u4e2a API\u3002\u8fd9\u6837\u505a\u662f\u4e3a\u4e86\u786e\u4fdd\u4e8b\u4ef6\u5728\u4e0d\u540c\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u4e00\u81f4\u7684\u5c5e\u6027\u3002<\/p>\n<h3><strong>25. \u4f60\u5bf9 React \u7684 refs \u6709\u4ec0\u4e48\u4e86\u89e3\uff1f<\/strong><\/h3>\n<p>Refs \u662f React \u4e2d\u5f15\u7528\u7684\u7b80\u5199\u3002\u5b83\u662f\u4e00\u4e2a\u6709\u52a9\u4e8e\u5b58\u50a8\u5bf9\u7279\u5b9a\u7684 React \u5143\u7d20\u6216\u7ec4\u4ef6\u7684\u5f15\u7528\u7684\u5c5e\u6027\uff0c\u5b83\u5c06\u7531\u7ec4\u4ef6\u6e32\u67d3\u914d\u7f6e\u51fd\u6570\u8fd4\u56de\u3002\u7528\u4e8e\u5bf9 render() \u8fd4\u56de\u7684\u7279\u5b9a\u5143\u7d20\u6216\u7ec4\u4ef6\u7684\u5f15\u7528\u3002\u5f53\u9700\u8981\u8fdb\u884c DOM \u6d4b\u91cf\u6216\u5411\u7ec4\u4ef6\u6dfb\u52a0\u65b9\u6cd5\u65f6\uff0c\u5b83\u4eec\u4f1a\u6d3e\u4e0a\u7528\u573a\u3002<\/p>\n<pre><code>class ReferenceDemo extends React.Component{\r\n     display() {\r\n         const name = this.inputDemo.value;\r\n         document.getElementById('disp').innerHTML = name;\r\n     }\r\nrender() {\r\n    return(        \r\n          &lt;div&gt;\r\n            Name: &lt;input type=\"text\" ref={input =&gt; this.inputDemo = input} \/&gt;\r\n            &lt;button name=\"Click\" onClick={this.display}&gt;Click&lt;\/button&gt;            \r\n            &lt;h2&gt;Hello &lt;span id=\"disp\"&gt;&lt;\/span&gt; !!!&lt;\/h2&gt;\r\n          &lt;\/div&gt;\r\n    );\r\n   }\r\n }\r\n\r\n<\/code><\/pre>\n<h3><strong>26. \u5217\u51fa\u4e00\u4e9b\u5e94\u8be5\u4f7f\u7528 Refs \u7684\u60c5\u51b5\u3002<\/strong><\/h3>\n<p>\u4ee5\u4e0b\u662f\u5e94\u8be5\u4f7f\u7528 refs \u7684\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\u9700\u8981\u7ba1\u7406\u7126\u70b9\u3001\u9009\u62e9\u6587\u672c\u6216\u5a92\u4f53\u64ad\u653e\u65f6<\/li>\n<li>\u89e6\u53d1\u5f0f\u52a8\u753b<\/li>\n<li>\u4e0e\u7b2c\u4e09\u65b9 DOM \u5e93\u96c6\u6210<\/li>\n<\/ul>\n<h3><strong>27. \u5982\u4f55\u6a21\u5757\u5316 React \u4e2d\u7684\u4ee3\u7801\uff1f<\/strong><\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528 export \u548c import \u5c5e\u6027\u6765\u6a21\u5757\u5316\u4ee3\u7801\u3002\u5b83\u4eec\u6709\u52a9\u4e8e\u5728\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d\u5355\u72ec\u7f16\u5199\u7ec4\u4ef6\u3002<\/p>\n<pre><code>\/\/ChildComponent.jsx\r\nexport default class ChildComponent extends React.Component {\r\n    render() {\r\n        return(           \r\n              &lt;div&gt;\r\n              \t&lt;h1&gt;This is a child component&lt;\/h1&gt;\r\n              &lt;\/div&gt;\r\n        );\r\n    }\r\n}\r\n \r\n\/\/ParentComponent.jsx\r\nimport ChildComponent from '.\/childcomponent.js';\r\nclass ParentComponent extends React.Component {    \r\n    render() {        \r\n        return(           \r\n             &lt;div&gt;               \r\n                &lt;App \/&gt;          \r\n             &lt;\/div&gt;       \r\n        );  \r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>28. \u5982\u4f55\u5728 React \u4e2d\u521b\u5efa\u8868\u5355<\/strong><\/h3>\n<p>React \u8868\u5355\u7c7b\u4f3c\u4e8e HTML \u8868\u5355\u3002\u4f46\u662f\u5728 React \u4e2d\uff0c\u72b6\u6001\u5305\u542b\u5728\u7ec4\u4ef6\u7684 state \u5c5e\u6027\u4e2d\uff0c\u5e76\u4e14\u53ea\u80fd\u901a\u8fc7 <code>setState()<\/code> \u66f4\u65b0\u3002\u56e0\u6b64\u5143\u7d20\u4e0d\u80fd\u76f4\u63a5\u66f4\u65b0\u5b83\u4eec\u7684\u72b6\u6001\uff0c\u5b83\u4eec\u7684\u63d0\u4ea4\u662f\u7531 JavaScript \u51fd\u6570\u5904\u7406\u7684\u3002\u6b64\u51fd\u6570\u53ef\u4ee5\u5b8c\u5168\u8bbf\u95ee\u7528\u6237\u8f93\u5165\u5230\u8868\u5355\u7684\u6570\u636e\u3002<\/p>\n<pre><code>handleSubmit(event) {\r\n    alert('A name was submitted: ' + this.state.value);\r\n    event.preventDefault();\r\n}\r\n \r\nrender() {\r\n    return (        \r\n        &lt;form onSubmit={this.handleSubmit}&gt;\r\n            &lt;label&gt;\r\n                Name:\r\n                &lt;input type=\"text\" value={this.state.value} onChange={this.handleSubmit} \/&gt;\r\n            &lt;\/label&gt;\r\n            &lt;input type=\"submit\" value=\"Submit\" \/&gt;\r\n        &lt;\/form&gt;\r\n    );\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>29. \u4f60\u5bf9\u53d7\u63a7\u7ec4\u4ef6\u548c\u975e\u53d7\u63a7\u7ec4\u4ef6\u4e86\u89e3\u591a\u5c11\uff1f<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>\u53d7\u63a7\u7ec4\u4ef6<\/strong><\/th>\n<th><strong>\u975e\u53d7\u63a7\u7ec4\u4ef6<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. \u6ca1\u6709\u7ef4\u6301\u81ea\u5df1\u7684\u72b6\u6001<\/td>\n<td>1. \u4fdd\u6301\u7740\u81ea\u5df1\u7684\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>2.\u6570\u636e\u7531\u7236\u7ec4\u4ef6\u63a7\u5236<\/td>\n<td>2.\u6570\u636e\u7531 DOM \u63a7\u5236<\/td>\n<\/tr>\n<tr>\n<td>3. \u901a\u8fc7 props \u83b7\u53d6\u5f53\u524d\u503c\uff0c\u7136\u540e\u901a\u8fc7\u56de\u8c03\u901a\u77e5\u66f4\u6539<\/td>\n<td>3. Refs \u7528\u4e8e\u83b7\u53d6\u5176\u5f53\u524d\u503c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><strong>30. \u4ec0\u4e48\u662f\u9ad8\u9636\u7ec4\u4ef6\uff08HOC\uff09\uff1f<\/strong><\/h3>\n<p>\u9ad8\u9636\u7ec4\u4ef6\u662f\u91cd\u7528\u7ec4\u4ef6\u903b\u8f91\u7684\u9ad8\u7ea7\u65b9\u6cd5\uff0c\u662f\u4e00\u79cd\u6e90\u4e8e React \u7684\u7ec4\u4ef6\u6a21\u5f0f\u3002 HOC \u662f\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u5728\u5b83\u4e4b\u5185\u5305\u542b\u53e6\u4e00\u4e2a\u7ec4\u4ef6\u3002\u5b83\u4eec\u53ef\u4ee5\u63a5\u53d7\u5b50\u7ec4\u4ef6\u63d0\u4f9b\u7684\u4efb\u4f55\u52a8\u6001\uff0c\u4f46\u4e0d\u4f1a\u4fee\u6539\u6216\u590d\u5236\u5176\u8f93\u5165\u7ec4\u4ef6\u4e2d\u7684\u4efb\u4f55\u884c\u4e3a\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a HOC \u662f\u201c\u7eaf\uff08Pure\uff09\u201d\u7ec4\u4ef6\u3002<\/p>\n<h3><strong>31. \u4f60\u80fd\u7528HOC\u505a\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>HOC\u53ef\u7528\u4e8e\u8bb8\u591a\u4efb\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u91cd\u7528\uff0c\u903b\u8f91\u548c\u5f15\u5bfc\u62bd\u8c61<\/li>\n<li>\u6e32\u67d3\u52ab\u6301<\/li>\n<li>\u72b6\u6001\u62bd\u8c61\u548c\u63a7\u5236<\/li>\n<li>Props \u63a7\u5236<\/li>\n<\/ul>\n<h3><strong>32. \u4ec0\u4e48\u662f\u7eaf\u7ec4\u4ef6\uff1f<\/strong><\/h3>\n<p><em>\u7eaf\uff08Pure\uff09<\/em> \u7ec4\u4ef6\u662f\u53ef\u4ee5\u7f16\u5199\u7684\u6700\u7b80\u5355\u3001\u6700\u5feb\u7684\u7ec4\u4ef6\u3002\u5b83\u4eec\u53ef\u4ee5\u66ff\u6362\u4efb\u4f55\u53ea\u6709 <strong>render()<\/strong> \u7684\u7ec4\u4ef6\u3002\u8fd9\u4e9b\u7ec4\u4ef6\u589e\u5f3a\u4e86\u4ee3\u7801\u7684\u7b80\u5355\u6027\u548c\u5e94\u7528\u7684\u6027\u80fd\u3002<\/p>\n<h3><strong>33. React \u4e2d key \u7684\u91cd\u8981\u6027\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>key \u7528\u4e8e\u8bc6\u522b\u552f\u4e00\u7684 Virtual DOM \u5143\u7d20\u53ca\u5176\u9a71\u52a8 UI \u7684\u76f8\u5e94\u6570\u636e\u3002\u5b83\u4eec\u901a\u8fc7\u56de\u6536 DOM \u4e2d\u5f53\u524d\u6240\u6709\u7684\u5143\u7d20\u6765\u5e2e\u52a9 React \u4f18\u5316\u6e32\u67d3\u3002\u8fd9\u4e9b key \u5fc5\u987b\u662f\u552f\u4e00\u7684\u6570\u5b57\u6216\u5b57\u7b26\u4e32\uff0cReact \u53ea\u662f\u91cd\u65b0\u6392\u5e8f\u5143\u7d20\u800c\u4e0d\u662f\u91cd\u65b0\u6e32\u67d3\u5b83\u4eec\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/p>\n<h2><strong>React Redux<\/strong><\/h2>\n<h3><strong>34. MVC\u6846\u67b6\u7684\u4e3b\u8981\u95ee\u9898\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>\u4ee5\u4e0b\u662fMVC\u6846\u67b6\u7684\u4e00\u4e9b\u4e3b\u8981\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5bf9 DOM \u64cd\u4f5c\u7684\u4ee3\u4ef7\u975e\u5e38\u9ad8<\/li>\n<li>\u7a0b\u5e8f\u8fd0\u884c\u7f13\u6162\u4e14\u6548\u7387\u4f4e\u4e0b<\/li>\n<li>\u5185\u5b58\u6d6a\u8d39\u4e25\u91cd<\/li>\n<li>\u7531\u4e8e\u5faa\u73af\u4f9d\u8d56\u6027\uff0c\u7ec4\u4ef6\u6a21\u578b\u9700\u8981\u56f4\u7ed5 models \u548c views \u8fdb\u884c\u521b\u5efa<\/li>\n<\/ul>\n<h3><strong>35. \u89e3\u91ca\u4e00\u4e0b Flux<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114746.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3033\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114746.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916114746\" width=\"817\" height=\"292\" \/><\/a><\/p>\n<p>Flux \u662f\u4e00\u79cd\u5f3a\u5236\u5355\u5411\u6570\u636e\u6d41\u7684\u67b6\u6784\u6a21\u5f0f\u3002\u5b83\u63a7\u5236\u6d3e\u751f\u6570\u636e\uff0c\u5e76\u4f7f\u7528\u5177\u6709\u6240\u6709\u6570\u636e\u6743\u9650\u7684\u4e2d\u5fc3 store \u5b9e\u73b0\u591a\u4e2a\u7ec4\u4ef6\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u6574\u4e2a\u5e94\u7528\u4e2d\u7684\u6570\u636e\u66f4\u65b0\u5fc5\u987b\u53ea\u80fd\u5728\u6b64\u5904\u8fdb\u884c\u3002 Flux \u4e3a\u5e94\u7528\u63d0\u4f9b\u7a33\u5b9a\u6027\u5e76\u51cf\u5c11\u8fd0\u884c\u65f6\u7684\u9519\u8bef\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>36. \u4ec0\u4e48\u662fRedux\uff1f<\/strong><\/h3>\n<p>Redux \u662f\u5f53\u4eca\u6700\u70ed\u95e8\u7684\u524d\u7aef\u5f00\u53d1\u5e93\u4e4b\u4e00\u3002\u5b83\u662f JavaScript \u7a0b\u5e8f\u7684\u53ef\u9884\u6d4b\u72b6\u6001\u5bb9\u5668\uff0c\u7528\u4e8e\u6574\u4e2a\u5e94\u7528\u7684\u72b6\u6001\u7ba1\u7406\u3002\u4f7f\u7528 Redux \u5f00\u53d1\u7684\u5e94\u7528\u6613\u4e8e\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u5e76\u663e\u793a\u4e00\u81f4\u7684\u884c\u4e3a\u3002<\/p>\n<h3><strong>37. Redux\u9075\u5faa\u7684\u4e09\u4e2a\u539f\u5219\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<ol>\n<li><strong><em>\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\uff1a<\/em><\/strong>\u6574\u4e2a\u5e94\u7528\u7684\u72b6\u6001\u5b58\u50a8\u5728\u5355\u4e2a store \u4e2d\u7684\u5bf9\u8c61\/\u72b6\u6001\u6811\u91cc\u3002\u5355\u4e00\u72b6\u6001\u6811\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8ddf\u8e2a\u968f\u65f6\u95f4\u7684\u53d8\u5316\uff0c\u5e76\u8c03\u8bd5\u6216\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li><strong><em>\u72b6\u6001\u662f\u53ea\u8bfb\u7684\uff1a<\/em><\/strong>\u6539\u53d8\u72b6\u6001\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u53bb\u89e6\u53d1\u4e00\u4e2a\u52a8\u4f5c\u3002\u52a8\u4f5c\u662f\u63cf\u8ff0\u53d8\u5316\u7684\u666e\u901a JS \u5bf9\u8c61\u3002\u5c31\u50cf state \u662f\u6570\u636e\u7684\u6700\u5c0f\u8868\u793a\u4e00\u6837\uff0c\u8be5\u64cd\u4f5c\u662f\u5bf9\u6570\u636e\u66f4\u6539\u7684\u6700\u5c0f\u8868\u793a\u3002<\/li>\n<li><strong><em>\u4f7f\u7528\u7eaf\u51fd\u6570\u8fdb\u884c\u66f4\u6539\uff1a<\/em><\/strong>\u4e3a\u4e86\u6307\u5b9a\u72b6\u6001\u6811\u5982\u4f55\u901a\u8fc7\u64cd\u4f5c\u8fdb\u884c\u8f6c\u6362\uff0c\u4f60\u9700\u8981\u7eaf\u51fd\u6570\u3002\u7eaf\u51fd\u6570\u662f\u90a3\u4e9b\u8fd4\u56de\u503c\u4ec5\u53d6\u51b3\u4e8e\u5176\u53c2\u6570\u503c\u7684\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115242.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3036\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115242.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115242\" width=\"547\" height=\"497\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>38. \u4f60\u5bf9\u201c\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u201d\u6709\u4ec0\u4e48\u7406\u89e3\uff1f<\/strong><\/h3>\n<p>Redux \u4f7f\u7528 \u201cStore\u201d \u5c06\u7a0b\u5e8f\u7684\u6574\u4e2a\u72b6\u6001\u5b58\u50a8\u5728\u540c\u4e00\u4e2a\u5730\u65b9\u3002\u56e0\u6b64\u6240\u6709\u7ec4\u4ef6\u7684\u72b6\u6001\u90fd\u5b58\u50a8\u5728 Store \u4e2d\uff0c\u5e76\u4e14\u5b83\u4eec\u4ece Store \u672c\u8eab\u63a5\u6536\u66f4\u65b0\u3002\u5355\u4e00\u72b6\u6001\u6811\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8ddf\u8e2a\u968f\u65f6\u95f4\u7684\u53d8\u5316\uff0c\u5e76\u8c03\u8bd5\u6216\u68c0\u67e5\u7a0b\u5e8f\u3002<\/p>\n<h3><strong>39. \u5217\u51fa Redux \u7684\u7ec4\u4ef6\u3002<\/strong><\/h3>\n<p>Redux \u7531\u4ee5\u4e0b\u7ec4\u4ef6\u7ec4\u6210\uff1a<\/p>\n<ol>\n<li><strong>Action<\/strong> \u2013 \u8fd9\u662f\u4e00\u4e2a\u7528\u6765\u63cf\u8ff0\u53d1\u751f\u4e86\u4ec0\u4e48\u4e8b\u60c5\u7684\u5bf9\u8c61\u3002<\/li>\n<li><strong>Reducer<\/strong> \u2013 \u8fd9\u662f\u4e00\u4e2a\u786e\u5b9a\u72b6\u6001\u5c06\u5982\u4f55\u53d8\u5316\u7684\u5730\u65b9\u3002<\/li>\n<li><strong>Store<\/strong> \u2013 \u6574\u4e2a\u7a0b\u5e8f\u7684\u72b6\u6001\/\u5bf9\u8c61\u6811\u4fdd\u5b58\u5728Store\u4e2d\u3002<\/li>\n<li><strong>View<\/strong> \u2013 \u53ea\u663e\u793a Store \u63d0\u4f9b\u7684\u6570\u636e\u3002<\/li>\n<\/ol>\n<h3><strong>40. \u6570\u636e\u5982\u4f55\u901a\u8fc7 Redux \u6d41\u52a8\uff1f<\/strong><\/h3>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115329.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3035\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/09\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115329.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200916115329\" width=\"673\" height=\"298\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>41. \u5982\u4f55\u5728 Redux \u4e2d\u5b9a\u4e49 Action\uff1f<\/strong><\/h3>\n<p>React \u4e2d\u7684 Action \u5fc5\u987b\u5177\u6709 type \u5c5e\u6027\uff0c\u8be5\u5c5e\u6027\u6307\u793a\u6b63\u5728\u6267\u884c\u7684 ACTION \u7684\u7c7b\u578b\u3002\u5fc5\u987b\u5c06\u5b83\u4eec\u5b9a\u4e49\u4e3a\u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u5e76\u4e14\u8fd8\u53ef\u4ee5\u5411\u5176\u6dfb\u52a0\u66f4\u591a\u7684\u5c5e\u6027\u3002\u5728 Redux \u4e2d\uff0caction \u88ab\u540d\u4e3a Action Creators \u7684\u51fd\u6570\u6240\u521b\u5efa\u3002\u4ee5\u4e0b\u662f Action \u548cAction Creator \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>function addTodo(text) {\r\n       return {\r\n                type: ADD_TODO,    \r\n                 text\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<h3><strong>42. \u89e3\u91ca Reducer \u7684\u4f5c\u7528\u3002<\/strong><\/h3>\n<p>Reducers \u662f\u7eaf\u51fd\u6570\uff0c\u5b83\u89c4\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u72b6\u6001\u600e\u6837\u56e0\u54cd\u5e94 ACTION \u800c\u6539\u53d8\u3002Reducers \u901a\u8fc7\u63a5\u53d7\u5148\u524d\u7684\u72b6\u6001\u548c action \u6765\u5de5\u4f5c\uff0c\u7136\u540e\u5b83\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u72b6\u6001\u3002\u5b83\u6839\u636e\u64cd\u4f5c\u7684\u7c7b\u578b\u786e\u5b9a\u9700\u8981\u6267\u884c\u54ea\u79cd\u66f4\u65b0\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u7684\u503c\u3002\u5982\u679c\u4e0d\u9700\u8981\u5b8c\u6210\u4efb\u52a1\uff0c\u5b83\u4f1a\u8fd4\u56de\u539f\u6765\u7684\u72b6\u6001\u3002<\/p>\n<h3><strong>43. Store \u5728 Redux \u4e2d\u7684\u610f\u4e49\u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<p>Store \u662f\u4e00\u4e2a JavaScript \u5bf9\u8c61\uff0c\u5b83\u53ef\u4ee5\u4fdd\u5b58\u7a0b\u5e8f\u7684\u72b6\u6001\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u65b9\u6cd5\u6765\u8bbf\u95ee\u72b6\u6001\u3001\u8c03\u5ea6\u64cd\u4f5c\u548c\u6ce8\u518c\u4fa6\u542c\u5668\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u6574\u4e2a\u72b6\u6001\/\u5bf9\u8c61\u6811\u4fdd\u5b58\u5728\u5355\u4e00\u5b58\u50a8\u4e2d\u3002\u56e0\u6b64\uff0cRedux \u975e\u5e38\u7b80\u5355\u4e14\u662f\u53ef\u9884\u6d4b\u7684\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u4e2d\u95f4\u4ef6\u4f20\u9012\u5230 store \u6765\u5904\u7406\u6570\u636e\uff0c\u5e76\u8bb0\u5f55\u6539\u53d8\u5b58\u50a8\u72b6\u6001\u7684\u5404\u79cd\u64cd\u4f5c\u3002\u6240\u6709\u64cd\u4f5c\u90fd\u901a\u8fc7 reducer \u8fd4\u56de\u4e00\u4e2a\u65b0\u72b6\u6001\u3002<\/p>\n<h3><strong>44. Redux\u4e0eFlux\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>Flux<\/strong><\/th>\n<th><strong>Redux<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. Store \u5305\u542b\u72b6\u6001\u548c\u66f4\u6539\u903b\u8f91<\/td>\n<td>1. Store \u548c\u66f4\u6539\u903b\u8f91\u662f\u5206\u5f00\u7684<\/td>\n<\/tr>\n<tr>\n<td>2. \u6709\u591a\u4e2a Store<\/td>\n<td>2. \u53ea\u6709\u4e00\u4e2a Store<\/td>\n<\/tr>\n<tr>\n<td>3. \u6240\u6709 Store \u90fd\u4e92\u4e0d\u5f71\u54cd\u4e14\u662f\u5e73\u7ea7\u7684<\/td>\n<td>3. \u5e26\u6709\u5206\u5c42 reducer \u7684\u5355\u4e00 Store<\/td>\n<\/tr>\n<tr>\n<td>4. \u6709\u5355\u4e00\u8c03\u5ea6\u5668<\/td>\n<td>4. \u6ca1\u6709\u8c03\u5ea6\u5668\u7684\u6982\u5ff5<\/td>\n<\/tr>\n<tr>\n<td>5. React \u7ec4\u4ef6\u8ba2\u9605 store<\/td>\n<td>5. \u5bb9\u5668\u7ec4\u4ef6\u662f\u6709\u8054\u7cfb\u7684<\/td>\n<\/tr>\n<tr>\n<td>6. \u72b6\u6001\u662f\u53ef\u53d8\u7684<\/td>\n<td>6. \u72b6\u6001\u662f\u4e0d\u53ef\u6539\u53d8\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><strong>45. Redux \u6709\u54ea\u4e9b\u4f18\u70b9\uff1f<\/strong><\/h3>\n<p>Redux \u7684\u4f18\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u7ed3\u679c\u7684\u53ef\u9884\u6d4b\u6027 &#8211;<\/strong> \u7531\u4e8e\u603b\u662f\u5b58\u5728\u4e00\u4e2a\u771f\u5b9e\u6765\u6e90\uff0c\u5373 store \uff0c\u56e0\u6b64\u4e0d\u5b58\u5728\u5982\u4f55\u5c06\u5f53\u524d\u72b6\u6001\u4e0e\u52a8\u4f5c\u548c\u5e94\u7528\u7684\u5176\u4ed6\u90e8\u5206\u540c\u6b65\u7684\u95ee\u9898\u3002<\/li>\n<li><strong>\u53ef\u7ef4\u62a4\u6027 &#8211;<\/strong> \u4ee3\u7801\u53d8\u5f97\u66f4\u5bb9\u6613\u7ef4\u62a4\uff0c\u5177\u6709\u53ef\u9884\u6d4b\u7684\u7ed3\u679c\u548c\u4e25\u683c\u7684\u7ed3\u6784\u3002<\/li>\n<li><strong>\u670d\u52a1\u5668\u7aef\u6e32\u67d3 &#8211;<\/strong> \u4f60\u53ea\u9700\u5c06\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u7684 store \u4f20\u5230\u5ba2\u6237\u7aef\u5373\u53ef\u3002\u8fd9\u5bf9\u521d\u59cb\u6e32\u67d3\u975e\u5e38\u6709\u7528\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f18\u5316\u5e94\u7528\u6027\u80fd\uff0c\u4ece\u800c\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/li>\n<li><strong>\u5f00\u53d1\u4eba\u5458\u5de5\u5177 &#8211;<\/strong> \u4ece\u64cd\u4f5c\u5230\u72b6\u6001\u66f4\u6539\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5b9e\u65f6\u8ddf\u8e2a\u5e94\u7528\u4e2d\u53d1\u751f\u7684\u6240\u6709\u4e8b\u60c5\u3002<\/li>\n<li><strong>\u793e\u533a\u548c\u751f\u6001\u7cfb\u7edf &#8211;<\/strong> Redux \u80cc\u540e\u6709\u4e00\u4e2a\u5de8\u5927\u7684\u793e\u533a\uff0c\u8fd9\u4f7f\u5f97\u5b83\u66f4\u52a0\u8ff7\u4eba\u3002\u4e00\u4e2a\u7531\u624d\u534e\u6a2a\u6ea2\u7684\u4eba\u7ec4\u6210\u7684\u5927\u578b\u793e\u533a\u4e3a\u5e93\u7684\u6539\u8fdb\u505a\u51fa\u4e86\u8d21\u732e\uff0c\u5e76\u5f00\u53d1\u4e86\u5404\u79cd\u5e94\u7528\u3002<\/li>\n<li><strong>\u6613\u4e8e\u6d4b\u8bd5 &#8211;<\/strong> Redux \u7684\u4ee3\u7801\u4e3b\u8981\u662f\u5c0f\u5de7\u3001\u7eaf\u7cb9\u548c\u72ec\u7acb\u7684\u529f\u80fd\u3002\u8fd9\u4f7f\u4ee3\u7801\u53ef\u6d4b\u8bd5\u4e14\u72ec\u7acb\u3002<\/li>\n<li><strong>\u7ec4\u7ec7 &#8211;<\/strong> Redux \u51c6\u786e\u5730\u8bf4\u660e\u4e86\u4ee3\u7801\u7684\u7ec4\u7ec7\u65b9\u5f0f\uff0c\u8fd9\u4f7f\u5f97\u4ee3\u7801\u5728\u56e2\u961f\u4f7f\u7528\u65f6\u66f4\u52a0\u4e00\u81f4\u548c\u7b80\u5355\u3002<\/li>\n<\/ul>\n<h2><strong>React \u8def\u7531<\/strong><\/h2>\n<h3><strong>46. \u4ec0\u4e48\u662fReact \u8def\u7531\uff1f<\/strong><\/h3>\n<p>React \u8def\u7531\u662f\u4e00\u4e2a\u6784\u5efa\u5728 React \u4e4b\u4e0a\u7684\u5f3a\u5927\u7684\u8def\u7531\u5e93\uff0c\u5b83\u6709\u52a9\u4e8e\u5411\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u65b0\u7684\u5c4f\u5e55\u548c\u6d41\u3002\u8fd9\u4f7f URL \u4e0e\u7f51\u9875\u4e0a\u663e\u793a\u7684\u6570\u636e\u4fdd\u6301\u540c\u6b65\u3002\u5b83\u8d1f\u8d23\u7ef4\u62a4\u6807\u51c6\u5316\u7684\u7ed3\u6784\u548c\u884c\u4e3a\uff0c\u5e76\u7528\u4e8e\u5f00\u53d1\u5355\u9875 Web \u5e94\u7528\u3002 React \u8def\u7531\u6709\u4e00\u4e2a\u7b80\u5355\u7684API\u3002<\/p>\n<h3><strong>47. \u4e3a\u4ec0\u4e48React Router v4\u4e2d\u4f7f\u7528 switch \u5173\u952e\u5b57 \uff1f<\/strong><\/h3>\n<p>\u867d\u7136 <strong>&#8220; ** \u7528\u4e8e\u5c01\u88c5 Router \u4e2d\u7684\u591a\u4e2a\u8def\u7531\uff0c\u5f53\u4f60\u60f3\u8981\u4ec5\u663e\u793a\u8981\u5728\u591a\u4e2a\u5b9a\u4e49\u7684\u8def\u7ebf\u4e2d\u5448\u73b0\u7684\u5355\u4e2a\u8def\u7ebf\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 \u201cswitch\u201d \u5173\u952e\u5b57\u3002\u4f7f\u7528\u65f6\uff0c<\/strong>&#8220;** \u6807\u8bb0\u4f1a\u6309\u987a\u5e8f\u5c06\u5df2\u5b9a\u4e49\u7684 URL \u4e0e\u5df2\u5b9a\u4e49\u7684\u8def\u7531\u8fdb\u884c\u5339\u914d\u3002\u627e\u5230\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u540e\uff0c\u5b83\u5c06\u6e32\u67d3\u6307\u5b9a\u7684\u8def\u5f84\u3002\u4ece\u800c\u7ed5\u8fc7\u5176\u5b83\u8def\u7ebf\u3002<\/p>\n<h3><strong>48. \u4e3a\u4ec0\u4e48\u9700\u8981 React \u4e2d\u7684\u8def\u7531\uff1f<\/strong><\/h3>\n<p>Router \u7528\u4e8e\u5b9a\u4e49\u591a\u4e2a\u8def\u7531\uff0c\u5f53\u7528\u6237\u5b9a\u4e49\u7279\u5b9a\u7684 URL \u65f6\uff0c\u5982\u679c\u6b64 URL \u4e0e Router \u5185\u5b9a\u4e49\u7684\u4efb\u4f55 \u201c\u8def\u7531\u201d \u7684\u8def\u5f84\u5339\u914d\uff0c\u5219\u7528\u6237\u5c06\u91cd\u5b9a\u5411\u5230\u8be5\u7279\u5b9a\u8def\u7531\u3002\u6240\u4ee5\u57fa\u672c\u4e0a\u6211\u4eec\u9700\u8981\u5728\u81ea\u5df1\u7684\u5e94\u7528\u4e2d\u6dfb\u52a0\u4e00\u4e2a Router \u5e93\uff0c\u5141\u8bb8\u521b\u5efa\u591a\u4e2a\u8def\u7531\uff0c\u6bcf\u4e2a\u8def\u7531\u90fd\u4f1a\u5411\u6211\u4eec\u63d0\u4f9b\u4e00\u4e2a\u72ec\u7279\u7684\u89c6\u56fe<\/p>\n<pre><code>&lt;switch&gt;\r\n    &lt;route exact path=\u2019\/\u2019 component={Home}\/&gt;\r\n    &lt;route path=\u2019\/posts\/:id\u2019 component={Newpost}\/&gt;\r\n    &lt;route path=\u2019\/posts\u2019   component={Post}\/&gt;\r\n&lt;\/switch&gt;\r\n\r\n<\/code><\/pre>\n<h3><strong>49. \u5217\u51fa React Router \u7684\u4f18\u70b9\u3002<\/strong><\/h3>\n<p>\u51e0\u4e2a\u4f18\u70b9\u662f\uff1a<\/p>\n<ol>\n<li>\u5c31\u50cf React \u57fa\u4e8e\u7ec4\u4ef6\u4e00\u6837\uff0c\u5728 React Router v4 \u4e2d\uff0cAPI \u662f <em>&#8216;All About Components&#8217;<\/em>\u3002\u53ef\u4ee5\u5c06 Router \u53ef\u89c6\u5316\u4e3a\u5355\u4e2a\u6839\u7ec4\u4ef6\uff08<strong>&#8220;<\/strong>\uff09\uff0c\u5176\u4e2d\u6211\u4eec\u5c06\u7279\u5b9a\u7684\u5b50\u8def\u7531\uff08<strong>&#8220;<\/strong>\uff09\u5305\u8d77\u6765\u3002<\/li>\n<li>\u65e0\u9700\u624b\u52a8\u8bbe\u7f6e\u5386\u53f2\u503c\uff1a\u5728 React Router v4 \u4e2d\uff0c\u6211\u4eec\u8981\u505a\u7684\u5c31\u662f\u5c06\u8def\u7531\u5305\u88c5\u5728 <strong>&#8220;<\/strong> \u7ec4\u4ef6\u4e2d\u3002<\/li>\n<li>\u5305\u662f\u5206\u5f00\u7684\uff1a\u5171\u6709\u4e09\u4e2a\u5305\uff0c\u5206\u522b\u7528\u4e8e Web\u3001Native \u548c Core\u3002\u8fd9\u4f7f\u6211\u4eec\u5e94\u7528\u66f4\u52a0\u7d27\u51d1\u3002\u57fa\u4e8e\u7c7b\u4f3c\u7684\u7f16\u7801\u98ce\u683c\u5f88\u5bb9\u6613\u8fdb\u884c\u5207\u6362\u3002<\/li>\n<\/ol>\n<h3><strong>50. React Router\u4e0e\u5e38\u89c4\u8def\u7531\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><\/h3>\n<figure>\n<table>\n<thead>\n<tr>\n<th><strong>\u4e3b\u9898<\/strong><\/th>\n<th><strong>\u5e38\u89c4\u8def\u7531<\/strong><\/th>\n<th><strong>React \u8def\u7531<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u53c2\u4e0e\u7684\u9875\u9762<\/strong><\/td>\n<td>\u6bcf\u4e2a\u89c6\u56fe\u5bf9\u5e94\u4e00\u4e2a\u65b0\u6587\u4ef6<\/td>\n<td>\u53ea\u6d89\u53ca\u5355\u4e2aHTML\u9875\u9762<\/td>\n<\/tr>\n<tr>\n<td><strong>URL \u66f4\u6539<\/strong><\/td>\n<td>HTTP \u8bf7\u6c42\u88ab\u53d1\u9001\u5230\u670d\u52a1\u5668\u5e76\u4e14\u63a5\u6536\u76f8\u5e94\u7684 HTML \u9875\u9762<\/td>\n<td>\u4ec5\u66f4\u6539\u5386\u53f2\u8bb0\u5f55\u5c5e\u6027<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4f53\u9a8c<\/strong><\/td>\n<td>\u7528\u6237\u5b9e\u9645\u5728\u6bcf\u4e2a\u89c6\u56fe\u7684\u4e0d\u540c\u9875\u9762\u5207\u6362<\/td>\n<td>\u7528\u6237\u8ba4\u4e3a\u81ea\u5df1\u6b63\u5728\u4e0d\u540c\u7684\u9875\u9762\u95f4\u5207\u6362<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u5e0c\u671b\u8fd9\u5957 React \u9762\u8bd5\u9898\u548c\u7b54\u6848\u80fd\u5e2e\u4f60\u51c6\u5907\u9762\u8bd5\u3002\u795d\u4e00\u5207\u987a\u5229\uff01<\/p>\n<p>\u4f5c\u8005\uff1a\u524d\u7aef\u5148\u950b<br \/>\n\u94fe\u63a5\uff1a<a class=\"url\" href=\"https:\/\/juejin.im\/post\/6844903806715559943\" target=\"_blank\">https:\/\/juejin.im\/post\/6844903806715559943<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u662f\u4e00\u4f4d\u6709\u62b1\u8d1f\u7684\u524d\u7aef\u7a0b\u5e8f\u5458\u5e76\u51c6\u5907\u9762\u8bd5\uff0c\u90a3\u4e48\u8fd9\u7bc7\u6587\u7ae0\u5f88\u9002\u5408\u4f60\u3002\u672c\u6587\u662f\u4f60\u5b66\u4e60\u548c\u9762\u8bd5 React \u6240\u9700\u77e5\u8bc6\u7684\u5b8c\u7f8e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[136,105],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3030"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3030"}],"version-history":[{"count":4,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3030\/revisions"}],"predecessor-version":[{"id":3045,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3030\/revisions\/3045"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}