{"id":38706,"date":"2023-06-20T04:56:17","date_gmt":"2023-07-12T03:35:12","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/"},"modified":"2024-04-30T09:44:00","modified_gmt":"2024-04-30T01:44:00","slug":"react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/","title":{"rendered":"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a"},"content":{"rendered":"<h1>React\u30cf\u30f3\u30ba\u30aa\u30f3 &#8211; \u4e2d\u6587\u7b80\u6d01\u7248<\/h1>\n<p>React\u5b9e\u6218 hands-on \u7ec3\u4e60<\/p>\n<h2>\u9996\u5148<\/h2>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5b9e\u8df5\u5b66\u4e60React\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u5982\u679c\u4f60\u4e86\u89e3JavaScript\u5e76\u80fd\u591f\u57fa\u672c\u9605\u8bfb\uff0c\u90a3\u4e48\u4f1a\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n<h2>\u57f9\u8bad\u7684\u6b65\u9aa4<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">React\u3068\u306f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">React\u306e\u74b0\u5883\u69cb\u7bc9<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">React\u3067\u30ab\u30a6\u30f3\u30c8\u30a2\u30d7\u30ea\uff0f\u30bf\u30b9\u30af\u7ba1\u7406\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u308b<\/ul>\n<h2>React \u662f\u4ec0\u4e48\uff1f<\/h2>\n<p>React\u662fJavaScript\u7684\u5e93\u3002\u901a\u8fc7\u4f7f\u7528React\uff0c\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u8bed\u6cd5\u8f7b\u677e\u5730\u521b\u5efaWEB\u9875\u9762\u3002<\/p>\n<h3>\u4f60\u4e0d\u7528HTML\u6216CSS\u6765\u5236\u4f5c\u5417\uff1f<\/h3>\n<p>\u5b66\u4e60\u521b\u5efa\u7f51\u9875\u65f6\uff0c\u9996\u5148\u4f1a\u5b66\u4e60\u4f7f\u7528HTML\u548cCSS\u8fdb\u884c\u5236\u4f5c\u3002\u5f53\u4f7f\u7528React\u521b\u5efa\u7f51\u9875\u65f6\uff0c\u6700\u7ec8\u4f1a\u6839\u636eReact\u7684\u4ee3\u7801\u751f\u6210\u5305\u62ecHTML\u548cCSS\u6587\u4ef6\u5728\u5185\u7684\u6587\u4ef6\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u6267\u884cnpm run build\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2abuild\u6587\u4ef6\u5939\uff0c\u5176\u4e2d\u5305\u542b\u4e86index.html\u548c\u5176\u4ed6\u5404\u79cd\u6587\u4ef6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5c06build\u6587\u4ef6\u5939\u653e\u5728\u670d\u52a1\u5668\u4e0a\u5373\u53ef\u53d1\u5e03\u7f51\u7ad9\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/9-0.jpeg\" alt=\"build\u56f3.jpg\" \/><\/div>\n<h3>React\u7684\u7279\u70b9<\/h3>\n<ul class=\"post-ul\">\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5358\u4f4d\u3067\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b<\/ul>\n<blockquote><p>\u7ec4\u4ef6\u662f\u6307\u7f51\u9875\u4e0a\u7684\u5404\u4e2a\u90e8\u5206\u3002\u4f8b\u5982\uff0c\u5934\u90e8\u3001\u6309\u94ae\u7b49\u7b49\u3002<\/p><\/blockquote>\n<ul class=\"post-ul\">\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u518d\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u7c21\u6f54\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308b<\/ul>\n<h2>React\u7684\u73af\u5883\u914d\u7f6e<\/h2>\n<p>\u5047\u8bbe\u5df2\u7ecf\u5b89\u88c5\u4e86Node.js\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5c06npm\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>npm update npm<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5b89\u88c5create-react-app\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>npm install -g create-react-app<\/ol>\n<p>\u73b0\u5728React\u7684\u5f00\u53d1\u73af\u5883\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\u3002<\/p>\n<h2>\u8bd5\u7740\u7528React\u5236\u4f5c\u8ba1\u6570\u5e94\u7528\uff0f\u4efb\u52a1\u7ba1\u7406\u5e94\u7528<\/h2>\n<h3>\u521b\u5efa\u5e76\u5c55\u793aReact\u5e94\u7528\u7a0b\u5e8f<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u524d\u5f80\u684c\u9762\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>cd \u684c\u9762\u8def\u5f84<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>npx create-react-app my-app<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5207\u6362\u5230\u521b\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>cd my-app<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u542f\u52a8\u670d\u52a1\u5668\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>npm start<\/ol>\n<p>\u5f53\u60a8\u8fd0\u884c\u6b64\u547d\u4ee4\u540e\uff0c\u670d\u52a1\u5668\u5c06\u542f\u52a8\u3002\u8bf7\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u8f93\u5165localhost:3000\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u770b\u5230\u7f51\u7ad9\u663e\u793a\u51fa\u6765\u3002<\/p>\n<h3>React\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e<\/h3>\n<p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e0bmy-app\u7684\u6784\u6210\u662f\u600e\u6837\u7684\u3002\u8bf7\u7528\u7f16\u8f91\u5668\u6253\u5f00my-app\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/24-0.png\" alt=\"tree.png\" \/><\/div>\n<p>\u5728\u6587\u4ef6\u5939\u4e2d\u6709\u51e0\u4e2a\u6587\u4ef6\u548c\u6587\u4ef6\u5939\uff0c\u4f46\u9996\u5148\u9700\u8981\u77e5\u9053\u7684\u662fpublic\u548csrc\u8fd9\u4e24\u4e2a\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">public\uff1aWeb\u3067\u516c\u958b\u3055\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u3044\u3066\u304a\u304f\u30d5\u30a9\u30eb\u30c0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">src\uff1aReact\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3084\u305d\u308c\u306b\u95a2\u9023\u3059\u308b\u30c7\u30fc\u30bf\u3092\u7f6e\u3044\u3066\u304a\u304f\u30d5\u30a9\u30eb\u30c0<\/ul>\n<h3>\u8ba9\u6211\u4eec\u5c1d\u8bd5\u6253\u5370HelloWorld<\/h3>\n<p>\u8ba9\u6211\u4eec\u5c1d\u8bd5\u663e\u793a\u4e00\u4e2a\u53ea\u5305\u542b\u201cHelloWorld\u201d\u6587\u5b57\u7684\u9875\u9762\uff0c\u4ee3\u66ff\u5f53\u524d\u663e\u793a\u7684\u9875\u9762\u3002<br \/>\n1. \u5220\u9664src\/App.js\u4e2d\u7684<\/p>\n<div>&#8230;<\/div>\n<p>\u3002<br \/>\n2. \u53d6\u800c\u4ee3\u4e4b\uff0c\u5199\u5165<\/p>\n<h2>HelloWorld<\/h2>\n<p>\u3002<\/p>\n<p>\u5f53\u60a8\u68c0\u67e5\u6d4f\u89c8\u5668\u65f6\uff0c\u6211\u8ba4\u4e3a\u60a8\u4f1a\u770b\u5230&#8221;HelloWorld&#8221;\u7684\u663e\u793a\u3002\u8fd9\u6837\uff0c\u5982\u679c\u8981\u66f4\u6539\u663e\u793a\u7684\u5185\u5bb9\uff0c\u9700\u8981\u66f4\u6539\u8fd4\u56de\u90e8\u5206\u3002\u5728\u8fd9\u91cc\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528HTML\u8bed\u6cd5\u8fdb\u884c\u7f16\u5199\u3002<\/p>\n<blockquote><p>\u4e25\u683c\u6765\u8bf4\uff0c\u5b83\u662f\u4e00\u79cd\u540d\u4e3aJSX\u7684\u8bed\u6cd5\u3002\u51e0\u4e4e\u6ca1\u6709\u548cHTML\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u5f3a\u884c\u8bf4\u7684\u8bdd\uff0c\u552f\u4e00\u7684\u533a\u522b\u662f\u5728JSX\u4e2d\uff0c\u6807\u7b7e\u5fc5\u987b\u8981\u6709\u95ed\u5408\uff0c\u6240\u4ee5<img decoding=\"async\" src=\"...\" \/>\u5fc5\u987b\u5199\u6210<img decoding=\"async\" src=\"...\" \/>\u6216\u8005<img \/>\u3002<\/p><\/blockquote>\n<h3>\u8868\u8fbe\u5904\u7406\u7684\u6d41\u7a0b<\/h3>\n<p>\u6211\u521a\u521a\u7f16\u8f91\u4e86App.js\uff0c\u4f46\u662f\u4fee\u6539\u7684\u6570\u636e\u4f1a\u4ee5\u4ec0\u4e48\u6837\u7684\u6d41\u7a0b\u8fdb\u884c\u5904\u7406\u5e76\u663e\u793a\u51fa\u6765\u5462\uff1f\u7b80\u800c\u8a00\u4e4b\uff0c\u521a\u521a\u4fee\u6539\u7684App.js\u6570\u636e\u4f1a\u4f20\u9012\u7ed9\u540c\u4e00\u5c42\u7ea7\u4e0b\u7684index.js\u540e\uff0c\u901a\u8fc7ReactDOM.render\u51fd\u6570\u5c06\u5176\u4f5c\u4e3apublic\/index.html\u4e2d\u7684<\/p>\n<div id=\"root\"><\/div>\n<p>\u7684\u5b50\u5143\u7d20\u6dfb\u52a0\u8fdb\u53bb\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/33-0.jpeg\" alt=\"\u30c6\u3099\u30fc\u30bf\u306e\u6d41\u308c.jpg\" \/><\/div>\n<h2>\u5c1d\u8bd5\u5236\u4f5c\u4e00\u4e2a\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f<\/h2>\n<p>\u7406\u89e3\u6d41\u7a0b\u4e4b\u540e\uff0c\u8ba9\u6211\u4eec\u5b9e\u9645\u4e0a\u521b\u5efa\u4e00\u4e2a\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u3002 \u8fd9\u6b21\u521b\u5efa\u7684\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5f53\u6309\u4e0b\u6309\u94ae\u65f6\uff0c\u663e\u793a\u7684\u6570\u5b57\u4f1a+1\u3002<\/p>\n<ol>\u5220\u9664\u51fd\u6570App() { &#8230; }\uff0c\u7136\u540e\u7c98\u8d34\u4ee5\u4e0b\u4ee3\u7801\u3002<\/ol>\n<pre class=\"post-pre\"><code>class App extends React.Component {\r\n  render() {\r\n    return (\r\n      &lt;div&gt;\r\n        &lt;h2&gt;\u30bf\u30a4\u30c8\u30eb&lt;\/h2&gt;\r\n        &lt;div&gt;0&lt;\/div&gt;\r\n        &lt;button&gt;COUNT UP&lt;\/button&gt;\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n<ol>\u5728\u5f00\u5934\u90e8\u5206\u6dfb\u52a0import React from &#8216;react&#8217;;\u3002<\/ol>\n<p>\u8bf7\u68c0\u67e5\u6d4f\u89c8\u5668\u4e2d\u662f\u5426\u663e\u793a\u4e86\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u9875\u9762\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06 function App() { &#8230; } \u5220\u9664\uff0c\u5e76\u5c06\u5176\u66ff\u6362\u4e3a class App extends React.Component { &#8230; }\uff0c\u4f46\u65e0\u8bba\u54ea\u79cd\u65b9\u5f0f\uff0c\u5728 return \u5185\u90e8\u7f16\u5199\u7684\u5143\u7d20\u90fd\u4f1a\u663e\u793a\u76f8\u540c\u7684\u7ed3\u679c\u3002\u6211\u4eec\u5c06\u5728\u7a0d\u540e\u89e3\u91ca\u4e3a\u4ec0\u4e48\u8981\u8fdb\u884c\u66ff\u6362\u4ee5\u53ca\u5177\u4f53\u7684\u533a\u522b\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u663e\u793a\u7684\u9875\u9762\u4e0a\u6709\u6807\u9898\u3001\u8ba1\u6570\u548c\u6309\u94ae\u3002\u76ee\u524d\uff0c\u5373\u4f7f\u6309\u4e0b\u6309\u94ae\uff0c\u8ba1\u6570\u4e5f\u4e0d\u4f1a\u6539\u53d8\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u4f7f\u7528React\u8bed\u6cd5\u6765\u6dfb\u52a0\u529f\u80fd\u3002<br \/>\n\u9996\u5148\uff0c\u6211\u4eec\u5c06\u66f4\u6539\u6807\u9898\u3002<br \/>\n\u5728render() { &#8230; }\u4e0a\u65b9\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<pre class=\"post-pre\"><code>constructor(props) {\r\n  super(props);\r\n  this.title = \"\u30ab\u30a6\u30f3\u30c8\u30a2\u30d7\u30ea\";\r\n}\r\n<\/code><\/pre>\n<ol>\u5c06\u6807\u9898\u66ff\u6362\u4e3a{ this.title }<\/ol>\n<p>\u5f53\u60a8\u786e\u8ba4\u6d4f\u89c8\u5668\u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u73b0\u6807\u9898\u5df2\u7ecf\u53d8\u6210\u4e86\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u662f\u56e0\u4e3a\u539f\u6765{this.title}\u4e2d\u7684this.title\u5df2\u88ab\u66ff\u6362\u4e3a\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u3002this.title\u662f\u5728\u6784\u9020\u51fd\u6570\u5185\u5b9a\u4e49\u7684\u3002<\/p>\n<p>\u5728React\u4e2d\uff0c\u5982\u679c\u60a8\u5728{}\u4e2d\u5199\u5165JavaScript\u53d8\u91cf\uff0cReact\u5c06\u4f1a\u5c06\u5176\u6e32\u67d3\u4e3aHTML\u5143\u7d20\u3002<\/p>\n<blockquote><p>\u5728JavaScript\u7684class\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528{\/* \u6ce8\u91ca\u6587 *\/}\u6765\u8fdb\u884c\u6ce8\u91ca\u3002<\/p>\n<p>\u6784\u9020\u51fd\u6570(props) { &#8230; }\u548csuper(props);\u7684\u5199\u6cd5\u662fJavaScript class\u7684\u7528\u6cd5\u3002\u5982\u679c\u4f60\u611f\u5174\u8da3\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u641c\u7d22&#8221;javascript class \u66f8\u304d\u65b9&#8221;\u7b49\u7b49\u3002\u53e6\u5916\uff0c\u5728React\u4e2d\uff0cconstructor\u548csuper\u7684\u53c2\u6570\u5e94\u4f20\u5165props\u3002\u4e00\u5f00\u59cb\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u8fd9\u662f\u4e00\u79cd\u666e\u904d\u7684\u5199\u6cd5\uff0c\u4e0d\u7528\u62c5\u5fc3\u3002<\/p><\/blockquote>\n<h3>\u4f7f\u7528State<\/h3>\n<p>\u63a5\u4e0b\u6765\uff0c\u5c06\u6dfb\u52a0\u4e00\u4e2a\u529f\u80fd\uff0c\u5f53\u6309\u4e0b\u6309\u94ae\u65f6\uff0c\u5b83\u4f1a\u8fdb\u884c\u8ba1\u6570\u589e\u52a0\u3002<\/p>\n<ol>\u5728super(props)\u7684\u4e0b\u65b9\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u3002<\/ol>\n<pre class=\"post-pre\"><code>this.state = {\r\n  count: 0\r\n};\r\n<\/code><\/pre>\n<ol>\u5728render()\u51fd\u6570\u4e0a\u65b9\u6dfb\u52a0\u4ee5\u4e0b\u65b9\u6cd5\u3002<\/ol>\n<pre class=\"post-pre\"><code>countUp() {\r\n  this.setState({count: this.state.count + 1 });\r\n}\r\n<\/code><\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5c06<\/ol>\n<\/li>\n<\/ol>\n<div>0<\/div>\n<p>\u66ff\u6362\u4e3a<\/p>\n<div>{ this.state.count }<\/div>\n<p>\u3002<br \/>\n\u5c06<button>COUNT UP<\/button>\u66ff\u6362\u4e3a<button> { this.countUp() } }&gt;COUNT UP<\/button>\u3002<\/p>\n<p>\u8bf7\u8fd4\u56de\u5230\u6d4f\u89c8\u5668\uff0c\u5e76\u5c1d\u8bd5\u70b9\u51fb\u6309\u94ae\u3002\u6211\u8ba4\u4e3a\u8ba1\u6570\u4f1a\u589e\u52a0\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528\u4e86 React \u7684 State \u529f\u80fd\u6765\u7ba1\u7406 count \u7684\u503c\u3002State \u53ef\u4ee5\u88ab\u89c6\u4e3a\u53d8\u91cf\u7684\u7ba1\u7406\u4f4d\u7f6e\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/54-0.jpeg\" alt=\"state.jpg\" \/><\/div>\n<p>\u7528\u6cd5\u5982\u4e0b\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">constructor\u5185\u3067this.state = { \u5909\u6570\u540d: \u5024, \u5909\u6570\u540d: \u5024, &#8230; }\u3068\u3057\u3066\u521d\u671f\u5024\u3092\u6307\u5b9a<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">this.state.\u5909\u6570\u540d\u3067\u5024\u306b\u30a2\u30af\u30bb\u30b9<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">this.setState({ \u5909\u6570\u540d: \u65b0\u3057\u3044\u5024 })\u3067\u5024\u3092\u5909\u66f4<\/ul>\n<p>\u4e3a\u4e86\u589e\u52a0count\u7684\u503c\uff0c\u9700\u8981\u6267\u884csetState\u65b9\u6cd5\u3002\u5728\u8fd9\u4e2a\u5e94\u7528\u4e2d\uff0c\u5f53\u6309\u4e0b\u6309\u94ae\u65f6\uff0c\u4f1a\u6267\u884ccountUp\u65b9\u6cd5\uff0c\u5e76\u5728countUp\u65b9\u6cd5\u4e2d\u8c03\u7528setState\u65b9\u6cd5\u3002<\/p>\n<p>\u5982\u679c\u60f3\u5728\u6309\u94ae\u88ab\u6309\u4e0b\u65f6\u6267\u884c\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06onClick={ \u5b9f\u884c\u3057\u305f\u3044\u95a2\u6570 }\u6dfb\u52a0\u4e3a\u5c5e\u6027\u3002\u8fd9\u6b21\u6211\u4eec\u5c06\u5176\u8bbe\u4e3aonClick={ () =&gt; { this.countUp() } }\u3002<\/p>\n<p>\u521b\u5efa\u8ba1\u6570\u5e94\u7528\u7a0b\u5e8f\u5230\u6b64\u4e3a\u6b62\uff0c\u4f46\u662f\u60a8\u8fd8\u53ef\u4ee5\u521b\u5efa\u7c7b\u4f3ccountDown\u7684\u51fd\u6570\uff0c\u5e76\u5c06\u5176\u5206\u914d\u7ed9\u6309\u94ae\u7684onClick\u5c5e\u6027\uff0c\u4ee5\u5b9e\u73b0\u5012\u8ba1\u65f6\u529f\u80fd\u3002<\/p>\n<h2>\u5c1d\u8bd5\u521b\u5efa\u4efb\u52a1\u7ba1\u7406\u5e94\u7528<\/h2>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u6765\u521b\u5efa\u4e00\u4e2a\u4efb\u52a1\u7ba1\u7406\u5e94\u7528\u3002\u8fd9\u4e2a\u8981\u521b\u5efa\u7684\u4efb\u52a1\u7ba1\u7406\u5e94\u7528\u5c06\u5177\u5907\u663e\u793a\u4efb\u52a1\u5217\u8868\u548c\u6dfb\u52a0\u4efb\u52a1\u7684\u529f\u80fd\u3002<\/p>\n<ol>\u5c06\u4ee5\u4e0b\u7684class App extends React.Component { &#8230; }\u66ff\u6362\u4e3a\uff1a<\/ol>\n<pre class=\"post-pre\"><code>class App extends React.Component {\r\n  render() {\r\n    return (\r\n      &lt;div&gt;\r\n        &lt;h2&gt;\u30bf\u30b9\u30af\u7ba1\u7406\u30a2\u30d7\u30ea&lt;\/h2&gt;\r\n        &lt;input \/&gt;\r\n        &lt;button&gt;\u8ffd\u52a0&lt;\/button&gt;\r\n        &lt;div&gt;1. \u672c\u3092\u8cb7\u3046&lt;\/div&gt;\r\n        &lt;div&gt;2. \u30e9\u30f3\u30cb\u30f3\u30b0\u3059\u308b&lt;\/div&gt;\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u786e\u8ba4\u5728\u6d4f\u89c8\u5668\u4e2d\u663e\u793a\u4e86\u4efb\u52a1\u7ba1\u7406\u5e94\u7528\u3002\u5f53\u524d\u663e\u793a\u7684\u4efb\u52a1\u662f\u624b\u52a8\u8f93\u5165\u7684\uff0c\u56e0\u6b64\u672a\u5b9e\u73b0\u5217\u8868\u529f\u80fd\u548c\u6dfb\u52a0\u529f\u80fd\u3002<\/p>\n<p>\u6211\u4eec\u6765\u6dfb\u52a0\u4e00\u9879\u5217\u8868\u529f\u80fd\u3002\u9996\u5148\uff0c\u6211\u4eec\u5c06\u4f7f\u7528State\u6765\u7ba1\u7406\u4efb\u52a1\u5185\u5bb9\u7684\u6570\u7ec4\u3002<\/p>\n<ol>\u5728`render()`\u51fd\u6570\u4e4b\u4e0a\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u3002<\/ol>\n<pre class=\"post-pre\"><code>constructor(props) {\r\n  super(props);\r\n  this.state = {\r\n    tasks: [\r\n      \"\u672c\u3092\u8cb7\u3046\",\r\n      \"\u30e9\u30f3\u30cb\u30f3\u30b0\u3059\u308b\",\r\n      \"\u725b\u4e73\u3092\u8cb7\u3046\"\r\n    ]\r\n  }\r\n}\r\n<\/code><\/pre>\n<ol>\u4f7f\u7528\u4e2d\u56fd\u666e\u901a\u8bdd\uff0c\u5c06\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u91ca\u4e49\uff1a<\/ol>\n<pre class=\"post-pre\"><code>&lt;div&gt;1. \u672c\u3092\u8cb7\u3046&lt;\/div&gt;\r\n&lt;div&gt;2. \u30e9\u30f3\u30cb\u30f3\u30b0\u3059\u308b&lt;\/div&gt;\r\n<\/code><\/pre>\n<p>\u8bf7\u7528\u4e2d\u6587\u6539\u5199\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>{\r\n  this.state.tasks.map( (task, index) =&gt; {\r\n    return &lt;div&gt;{ index + 1 }. { task }&lt;\/div&gt;\r\n  })\r\n}\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u68c0\u67e5\u6d4f\u89c8\u5668\u65f6\uff0c\u4f60\u4f1a\u53d1\u73b0\u5df2\u7ecf\u663e\u793a\u4e86\u5728State\u7684tasks\u4e2d\u7ba1\u7406\u7684\u4efb\u52a1\u3002\u4e0b\u9762\u6211\u5c06\u6309\u7167\u987a\u5e8f\u89e3\u91ca\u7ecf\u8fc7\u91cd\u5199\u7684\u5185\u5bb9\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">1.\u3067\u3001\u30bf\u30b9\u30af\u3092\u7ba1\u7406\u3059\u308btasks\u914d\u5217\u3092State\u306e\u5909\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3002<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">2.\u3067\u3001tasks\u914d\u5217\u306e\u4e2d\u8eab\u3092\u53d6\u308a\u51fa\u3057\u3066\u8868\u793a\u3002<\/ul>\n<p>\u5728\u4e2d\u56fd\uff0c\u4ee5\u4e0b\u662f\u5bf9\u8be5\u53e5\u7684\u4e00\u79cd\u7ffb\u8bd1\uff1a<br \/>\n\u8fd9\u4e2a\u53e5\u5b50\u6709\u70b9\u590d\u6742\uff0c\u4f46\u662f\u5982\u679c\u5206\u89e3\u5f00\u6765\u8003\u8651\uff0c\u5176\u5b9e\u5e76\u4e0d\u90a3\u4e48\u96be\u3002<\/p>\n<p>\u91cd\u70b9\u662f\uff0c<br \/>\n\u6ce8\u610f\u4e8b\u9879\u662f\uff0c<br \/>\n\u8981\u70b9\u662f\uff0c<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30a2\u30ed\u30fc\u95a2\u6570\u8868\u8a18<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">map\u30e1\u30bd\u30c3\u30c9<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">return\u306e\u5024<\/ul>\n<p>\u4ee5\u4e0b\u662f\u4e09\u4e2a\u9009\u9879\u3002<\/p>\n<h4>\u7bad\u5934\u51fd\u6570\u8868\u793a\u6cd5<\/h4>\n<p>\u9996\u5148\u662f\u7bad\u5934\u51fd\u6570\u7684\u8868\u793a\u6cd5\uff0c\u5b83\u662f\u4e00\u79cd\u7b80\u6d01\u8868\u793a\u4f20\u7edf\u51fd\u6570\u7684\u65b9\u6cd5\u3002<\/p>\n<pre class=\"post-pre\"><code>\/\/ \u5f93\u6765\r\nfunction sayHi(name) {\r\n  const msg = \"hi \" + name;\r\n  console.log(msg);\r\n}\r\nsayHi(\"Bob\"); \/\/ hi Bob\r\n\r\n\/\/ \u30a2\u30ed\u30fc\u95a2\u6570\u8868\u8a18\r\nconst sayHi = (name) =&gt; {\r\n  const msg = \"hi \" + name;\r\n  console.log(msg);\r\n};\r\nsayHi(\"Bob\"); \/\/ hi Bob\r\n<\/code><\/pre>\n<p>\u53ea\u8981\u719f\u6089\u4e86\uff0c\u5c31\u4e0d\u4f1a\u96be\u3002\u73b0\u5728\u53ea\u8981\u4f60\u80fd\u77e5\u9053\u6709\u8fd9\u79cd\u5199\u6cd5\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h4>map\u65b9\u6cd5<\/h4>\n<p>map\u65b9\u6cd5\u662f\u4e00\u4e2a\u7528\u4e8e\u5bf9\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u5904\u7406\u7684\u65b9\u6cd5\uff0c<br \/>\n\u53ef\u4ee5\u901a\u8fc7\u6570\u7ec4.map(\u5904\u7406\u51fd\u6570)\u8fd9\u6837\u7684\u5f62\u5f0f\u6765\u8c03\u7528\u3002<br \/>\n\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u8981\u5f97\u5230\u4e00\u4e2a\u7531\u6570\u7ec4array1\u7684\u6bcf\u4e2a\u5143\u7d20\u4e58\u4ee52\u5f97\u5230\u7684\u65b0\u6570\u7ec4array2\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\u5199\u4f5c\u3002<\/p>\n<pre class=\"post-pre\"><code>const array1 = [2, 4, 5, 8];\r\nconst array2 = array1.map( (value) =&gt; {\r\n  return value * 2;\r\n});\r\nconsole.log(array2); \/\/ [ 4, 8, 10, 16 ]\r\n<\/code><\/pre>\n<blockquote><p>map\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u5b83\u63a5\u6536\u6570\u7ec4\u7684\u5143\u7d20\u4f5c\u4e3a\u5176\u53c2\u6570\u3002\u5982\u679c\u63d0\u4f9b\u4e86\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u53ef\u4ee5\u83b7\u53d6\u63d0\u53d6\u5143\u7d20\u7684\u7d22\u5f15\u3002<\/p><\/blockquote>\n<h4>\u8fd4\u56de\u503c zh\u00ed)<\/h4>\n<p>\u5173\u4e8e\u8fd4\u56de\u503c\u7684\u6700\u540e\u4e00\u70b9\u3002\u5728React\u4e2d\uff0c\u53ef\u4ee5\u5c06HTML\u5143\u7d20\u89c6\u4e3a\u4e00\u4e2a\u503c\u3002\u4f8b\u5982\uff0c<\/p>\n<pre class=\"post-pre\"><code>const element = &lt;h2&gt;\u30bf\u30b9\u30af\u7ba1\u7406\u30a2\u30d7\u30ea&lt;\/h2&gt;\r\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u5904\u7406\u7c7b\u4f3c\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5728\u8003\u8651\u4ee5\u4e0a\u56e0\u7d20\u4e4b\u540e\uff0c\u518d\u6765\u770b\u4e00\u4e0b\u7ecf\u8fc72\u6b65\u9aa4\u66ff\u6362\u7684\u90e8\u5206\u3002<\/p>\n<pre class=\"post-pre\"><code>{\r\n  this.state.tasks.map( (task, index) =&gt; {\r\n    return &lt;div&gt;{index + 1}. {task}&lt;\/div&gt;\r\n  })\r\n}\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5bf9tasks\u6570\u7ec4\u4f7f\u7528\u4e86map\u65b9\u6cd5\uff0c\u5e76\u5728map\u65b9\u6cd5\u7684\u53c2\u6570\u4e2d\u4f7f\u7528\u4e86\u7bad\u5934\u51fd\u6570\u6765\u5904\u7406\u6240\u9700\u5185\u5bb9\u3002\u5728map\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e2d\uff0c\u8fd4\u56de\u4e86HTML\u5143\u7d20\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u60f3\u8981\u5b9e\u73b0\u4efb\u52a1\u7684\u6dfb\u52a0\u529f\u80fd\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728State\u4e2d\u6dfb\u52a0taskContent\u5c5e\u6027\uff1a&#8221;&#8221;\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728input\u6807\u7b7e\u7684\u5c5e\u6027\u4e2d\u6dfb\u52a0value={ this.state.taskContent }\u548conChange={(e) =&gt; { this.setState({ taskContent: e.target.value }) }}\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728button\u6807\u7b7e\u7684\u5c5e\u6027\u4e2d\u6dfb\u52a0onClick={ () =&gt; { this.addTask() } }\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5728render() { &#8230; }\u7684\u4e0a\u65b9\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u3002<\/ol>\n<pre class=\"post-pre\"><code>addTask() {\r\n  let tasks = this.state.tasks;\r\n  tasks.push(this.state.taskContent);\r\n  this.setState({tasks: tasks});\r\n  this.state.taskContent = \"\";\r\n}\r\n<\/code><\/pre>\n<p>\u8bf7\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u5c06\u9002\u5f53\u7684\u4efb\u52a1\u5185\u5bb9\u8f93\u5165\u5230\u6587\u672c\u6846\u4e2d\uff0c\u7136\u540e\u70b9\u51fb\u6dfb\u52a0\u6309\u94ae\u3002\u60a8\u4f1a\u770b\u5230\u4efb\u52a1\u5df2\u7ecf\u88ab\u6dfb\u52a0\u4e86\u3002<\/p>\n<p>\u5982\u679c\u6309\u7167\u8ffd\u8a18\u7684\u5167\u5bb9\u4f86\u9032\u884c\u8aaa\u660e\u7684\u8a71\uff0c<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">1.\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5024\u3092\u4fdd\u6301\u3059\u308btaskContent\u5909\u6570\u3092State\u306b\u3066\u521d\u671f\u5316<\/ul>\n<\/li>\n<\/ul>\n<p>2.\u3067\u306f\u3001<\/p>\n<p>taskContent\u306e\u5024\u3092\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u8868\u793a<br \/>\n\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5165\u529b\u3055\u308c\u305f\u5024\u3092taskContent\u306b\u53cd\u6620<\/p>\n<p>3.\u3067\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u6642\u306baddTask\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u6307\u5b9a<br \/>\n4.\u3067addTask\u95a2\u6570\u3092\u5b9a\u7fa9<\/p>\n<p>\u901a\u8fc7addTask\u51fd\u6570\u5c06taskContent\u7684\u503c\u6dfb\u52a0\u5230State\u7684tasks\u6570\u7ec4\u4e2d\u3002<\/p>\n<h3>\u7ec4\u4ef6\u548c\u5c5e\u6027<\/h3>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u5df2\u7ecf\u5b9e\u73b0\u4e86\u5217\u8868\u529f\u80fd\u548c\u6dfb\u52a0\u529f\u80fd\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u5f15\u5165\u7ec4\u4ef6\u5316\u7684\u8bbe\u8ba1\u601d\u60f3\uff0c\u5c06\u4efb\u52a1\u7684\u663e\u793a\u90e8\u5206\u8fdb\u884c\u7ec4\u4ef6\u5316\u3002\u901a\u8fc7\u7ec4\u4ef6\u5316\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u66f4\u7b80\u6d01\u7684\u4ee3\u7801\u8fdb\u884c\u63cf\u8ff0\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728src\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2acomponents\u6587\u4ef6\u5939\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728\u521b\u5efa\u7684components\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aTask.js\u7684\u6587\u4ef6\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5728Task.js\u4e2d\u7c98\u8d34\u4ee5\u4e0b\u5185\u5bb9\u3002<\/ol>\n<pre class=\"post-pre\"><code>import React from 'react';\r\n\r\nclass Task extends React.Component {\r\n  constructor(props) {\r\n    super(props);\r\n    this.number = props.number;\r\n    this.task = props.task;\r\n  }\r\n  render() {\r\n    return (\r\n      &lt;div&gt;\r\n        { this.number }. { this.task }\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n\r\nexport default Task;\r\n<\/code><\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728App.js\u7684\u5f00\u5934\u90e8\u5206\uff0c\u6dfb\u52a0import Task from &#8216;.\/components\/Task.js&#8217;;\u4ee5\u5bfc\u5165Task.js\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>\u5c06map\u65b9\u6cd5\u8fd4\u56de\u503c\u4e2d\u7684<\/p>\n<div>&#8230;<\/div>\n<p>\u66ff\u6362\u4e3a\u3002<\/p>\n<p>\u8bf7\u786e\u8ba4\u60a8\u7684\u6d4f\u89c8\u5668\u662f\u5426\u6b63\u5e38\uff0c\u5e76\u786e\u8ba4\u9875\u9762\u662f\u5426\u6b63\u786e\u663e\u793a\u3002<\/p>\n<p>\u9010\u6b65\u89e3\u8aaa\u6b65\u9a5f\u3002 b\u00f9)<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30bf\u30b9\u30af\u3092\u8868\u793a\u3059\u308b\u30d1\u30fc\u30c4\u3092Task\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3057\u3066\u7f6e\u304d\u63db\u3048\u305f\u3044<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u307e\u3068\u3081\u308bcomponents\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u4e2d\u306bTask.js\u3092\u4f5c\u6210<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Task.js\u306e\u4e2d\u8eab\u3082App.js\u3068\u540c\u69d8\u306e\u69cb\u9020\u3067\u3001Task\u30af\u30e9\u30b9\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u3066\u3044\u308b<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u305d\u306e\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305fTask\u30af\u30e9\u30b9\u3092App.js\u306e\u5192\u982d\u90e8\u5206\u3067\u30a4\u30f3\u30dd\u30fc\u30c8<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">App.js\u306emap\u30e1\u30bd\u30c3\u30c9\u306e\u623b\u308a\u5024\u3068\u3057\u3066\u3092\u7f6e\u304f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u3068\u3044\u3046\u6d41\u308c\u306b\u306a\u308a\u307e\u3059\u3002<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u3053\u3053\u3067\u3001\u306e&#8230;\u306b\u5f53\u305f\u308b\u90e8\u5206\u3092\u898b\u3066\u307f\u307e\u3059\u3002number={index + 1} task={task}\u3068\u3042\u308a\u307e\u3059\u304c\u3001\u3053\u3053\u3067Task\u306bnumber\u3068task\u3068\u3044\u3046props\u3092\u6e21\u3057\u3066\u3044\u307e\u3059\u3002props\u3068\u306f\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u6e21\u3059\u5024\u306e\u3053\u3068\u3067\u3059\u3002<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u3053\u306e2\u3064\u306eprops\u304c\u3069\u306e\u3088\u3046\u306b\u4f7f\u308f\u308c\u3066\u3044\u308b\u304bTask.js\u3092\u78ba\u8a8d\u3057\u3066\u307f\u308b\u3068\u3001constructor\u5185\u3067this.number = props.number; this.task = props.task;<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u3068\u3057\u3066\u30af\u30e9\u30b9\u5185\u306e\u5909\u6570\u306b\u6e21\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u6e21\u3055\u308c\u305fprops \u306e\u5024\u306f\u3001props.props\u540d\u3068\u3059\u308b\u3053\u3068\u3067\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/ul>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/108-0.jpeg\" alt=\"\u30b3\u30f3\u30db\u309a\u30fc\u30cd\u30f3\u30c8\u3068props.jpg\" \/><\/div>\n<p>\u6216\u8bb8\u5728\u672c\u6b21\u7684\u4f8b\u5b50\u4e2d\uff0c\u4f60\u53ef\u80fd\u6ca1\u6709\u592a\u591a\u5730\u611f\u53d7\u5230\u7ec4\u4ef6\u5316\u7684\u597d\u5904\uff0c\u4f46\u5f53\u5f00\u53d1\u89c4\u6a21\u7a0d\u5fae\u5927\u4e00\u4e9b\u65f6\uff0c\u4ece\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7ba1\u7406\u7684\u4fbf\u5229\u6027\u4ee5\u53ca\u53ef\u91cd\u7528\u6027\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u7ec4\u4ef6\u5316\u7684\u597d\u5904\u5c31\u4f1a\u53d8\u5f97\u66f4\u52a0\u660e\u663e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u5b8c\u6210\u4e86\u4e24\u4e2a\u5e94\u7528\u7684\u5b9e\u65bd\uff01<\/p>\n<h3>\u51fd\u6570\u7ec4\u4ef6\u662f\u4ec0\u4e48<\/h3>\n<p>\u5728React\u4e2d\uff0c\u7ec4\u4ef6\u6709\u4e24\u79cd\u7c7b\u578b\uff1a\u7c7b\u7ec4\u4ef6\u548c\u51fd\u6570\u7ec4\u4ef6\u3002<br \/>\n\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u6240\u5199\u7684\u7ec4\u4ef6\u90fd\u662f\u7c7b\u7ec4\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>class \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u540d extends React.component {\r\n  render() {\r\n    return (\r\n      &lt;div&gt;\r\n        \u8868\u793a\u5185\u5bb9\r\n      &lt;\/div&gt;\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u4e00\u79cd\u662f\u51fd\u6570\u7ec4\u4ef6\u7684\u4e66\u5199\u65b9\u5f0f\u5982\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>\/\/ \u30a2\u30ed\u30fc\u95a2\u6570\u8868\u8a18\u3067\u66f8\u304b\u308c\u308b\u3053\u3068\u3082\u3042\u308b\r\nfunction \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u540d() {\r\n  return (\r\n    &lt;div&gt;\r\n      \u8868\u793a\u5185\u5bb9\r\n    &lt;\/div&gt;\r\n  );\r\n}\r\n<\/code><\/pre>\n<p>\u51fd\u6570\u7ec4\u4ef6\u76f8\u8f83\u4e8e\u7c7b\u7ec4\u4ef6\u5728\u4e66\u5199\u4e0a\u66f4\u52a0\u7b80\u6d01\u3002\u867d\u7136\u57fa\u672c\u4e0a\u51fd\u6570\u7ec4\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u7ec4\u4ef6\u80fd\u505a\u7684\u4e8b\u60c5\uff0c\u4f46\u662f\u7531\u4e8e\u9700\u8981\u4f7f\u7528\u7a0d\u5fae\u590d\u6742\u7684\u8bed\u6cd5\uff0c\u6240\u4ee5\u6211\u8ba4\u4e3a\u5728\u719f\u6089\u7c7b\u7ec4\u4ef6\u4e4b\u540e\u518d\u5c1d\u8bd5\u4f7f\u7528\u51fd\u6570\u7ec4\u4ef6\u4f1a\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n<blockquote><p>\u9996\u5148\uff0c\u5c06\u51fd\u6570App()\u7684\u5b9a\u4e49\u5220\u9664\uff0c\u5e76\u66ff\u6362\u4e3a\u7c7b\u7ec4\u4ef6\u662f\u56e0\u4e3a\u4ee5\u4e0b\u539f\u56e0\u3002<\/p><\/blockquote>\n<p>React\u30cf\u30f3\u30ba\u30aa\u30f3\u306f\u3053\u3053\u307e\u3067\u3067\u3059\u3002\u304a\u75b2\u308c\u3055\u307e\u3067\u3057\u305f\u3002<\/p>\n<h2>\u6211\u4ecb\u7ecd\u4e0d\u5b8c\u7684\u4e8b\u60c5<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">ReactHooks<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">ReactRouter<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Redux<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>React\u30cf\u30f3\u30ba\u30aa\u30f3 &#8211; \u4e2d\u6587\u7b80\u6d01\u7248 React\u5b9e\u6218 hands-on \u7ec3\u4e60 \u9996\u5148 \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38706","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/react\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\" \/>\n<meta property=\"og:description\" content=\"React\u30cf\u30f3\u30ba\u30aa\u30f3 &#8211; \u4e2d\u6587\u7b80\u6d01\u7248 React\u5b9e\u6218 hands-on \u7ec3\u4e60 \u9996\u5148 \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/react\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-12T03:35:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T01:44:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/9-0.jpeg\" \/>\n<meta name=\"author\" content=\"\u5b87, \u534e\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5b87, \u534e\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/\",\"name\":\"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-07-12T03:35:12+00:00\",\"dateModified\":\"2024-04-30T01:44:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458\",\"name\":\"\u5b87, \u534e\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g\",\"caption\":\"\u5b87, \u534e\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yuhua\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/react\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\/","og_locale":"zh_CN","og_type":"article","og_title":"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a","og_description":"React\u30cf\u30f3\u30ba\u30aa\u30f3 &#8211; \u4e2d\u6587\u7b80\u6d01\u7248 React\u5b9e\u6218 hands-on \u7ec3\u4e60 \u9996\u5148 \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/react\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-07-12T03:35:12+00:00","article_modified_time":"2024-04-30T01:44:00+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d360d37434c4406c6e5a2\/9-0.jpeg"}],"author":"\u5b87, \u534e","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u5b87, \u534e","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/","name":"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-07-12T03:35:12+00:00","dateModified":"2024-04-30T01:44:00+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"React\u624b\u628a\u624b\u4f53\u9a8c\u5de5\u4f5c\u574a"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/513018e4e121d3add1b7c5de8be21458","name":"\u5b87, \u534e","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/63cd45cbc05a35fc4ff7637a163c83c4962ef58d27472726c3a3e0c9c5194f0f?s=96&d=mm&r=g","caption":"\u5b87, \u534e"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yuhua\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e6%89%8b%e6%8a%8a%e6%89%8b%e4%bd%93%e9%aa%8c%e5%b7%a5%e4%bd%9c%e5%9d%8a\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=38706"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38706\/revisions"}],"predecessor-version":[{"id":91158,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38706\/revisions\/91158"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=38706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=38706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=38706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}