{"id":2874,"date":"2020-04-19T19:55:32","date_gmt":"2020-04-19T11:55:32","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2874"},"modified":"2026-08-17T12:23:56","modified_gmt":"2026-08-17T04:23:56","slug":"%e3%80%8c%e6%8e%a8%e8%8d%90%e3%80%8dreact-%e9%80%9a%e4%bf%a1%e4%b9%8b-redux%ef%bc%8c%e7%9c%8b%e8%bf%99%e4%b8%80%e7%af%87%e5%b0%b1%e8%83%bd%e6%8e%8c%e6%8f%a1","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2874","title":{"rendered":"\u300c\u63a8\u8350\u300dReact \u901a\u4fe1\u4e4b Redux\uff0c\u770b\u8fd9\u4e00\u7bc7\u5c31\u80fd\u638c\u63e1"},"content":{"rendered":"<h1 class=\"pgc-h-center-line\">\u80cc\u666f<\/h1>\n<p>React \u7ec4\u4ef6 componentDidMount \u7684\u65f6\u5019\u521d\u59cb\u5316 Model\uff0c\u5e76\u76d1\u542c Model \u7684 change \u4e8b\u4ef6\uff0c\u5f53 Model \u53d1\u751f\u6539\u53d8\u65f6\u8c03\u7528 React \u7ec4\u4ef6\u7684 setState \u65b9\u6cd5\u91cd\u65b0 render \u6574\u4e2a\u7ec4\u4ef6\uff0c\u6700\u540e\u5728\u7ec4\u4ef6 componentWillUnmount \u7684\u65f6\u5019\u53d6\u6d88\u76d1\u542c\u5e76\u9500\u6bc1 Model\u3002<\/p>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/redux1.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2876\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/redux1.png\" alt=\"redux1\" width=\"620\" height=\"469\"><\/a><\/div>\n<h1 class=\"pgc-h-center-line\">\u7b2c\u4e00\u90e8\u5206 Redux\u7684\u51fa\u73b0<\/h1>\n<blockquote class=\"article-blockquote\"><p>\u5b58\u5728\u5373\u5408\u7406<\/p><\/blockquote>\n<p>\u5982<strong>\u4e0b\u56fe\u5de6\u4fa7<\/strong>\u6240\u793a\uff0creact\u5355\u5411\u6d41\u52a8\u7684\u7279\u6027\uff0c\u5bfc\u81f4\u5728\u590d\u6742\u7684\u72b6\u6001\u7ba1\u7406\u9762\u524d\uff0c\u4f1a\u8d8a\u6765\u8d8a\u9ebb\u70e6\u3002Redux\u7684\u51fa\u73b0\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3state\u91cc\u9762\u7684\u6570\u636e\u95ee\u9898\u3002<\/p>\n<p>\u5982<strong>\u4e0b\u56fe\u53f3\u4fa7<\/strong>\u6240\u793a\uff0credux\u7ef4\u62a4\u5355\u4e00\u72b6\u6001\u5e93\u3002<\/p>\n<p>Redux\u4e09\u5927\u7279\u6027\uff1a<\/p>\n<p>1 \u552f\u4e00\u6570\u636e\u6e90<\/p>\n<p>2 \u4fdd\u6301\u53ea\u8bfb\u72b6\u6001<\/p>\n<p>3 \u6570\u636e\u6539\u53d8\u53ea\u80fd\u901a\u8fc7\u7eaf\u51fd\u6570\u6765\u6267\u884c<\/p>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/redux20200419194631.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2877\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/redux20200419194631.png\" alt=\"redux20200419194631\" width=\"560\" height=\"325\"><\/a><\/div>\n<h1 class=\"pgc-h-center-line\">\u7b2c\u4e8c\u90e8\u5206 Redux\u6982\u5ff5<\/h1>\n<h1 class=\"pgc-h-center-line\">\u4e00\u3001\u7c97\u7565\u8ba4\u8bc6<\/h1>\n<p>\u9996\u5148\u56de\u60f3\u4e0b\uff0c\u66fe\u7ecf\u4f60\u53bb\u56fe\u4e66\u9986\u501f\u4e66\u7684\u573a\u666f+\u4e0a\u56fe\u53f3\u4fa7\u6811\u56fe\u3002<\/p>\n<ul class=\"\">\n<li><strong>\u4f60<\/strong>\u53bb\u56fe\u4e66\u9986\uff1b<\/li>\n<li><strong>\u8be2\u95ee<\/strong>\u7ba1\u7406\u5458\u662f\u5426\u6709\u300a\u897f\u90e8\u4e16\u754ciii\u300b\u8fd9\u672c\u4e66\uff1b<\/li>\n<li>\u7ba1\u7406\u5458<strong>\u67e5\u9605<\/strong>\u5e93\u5b58\uff1b<\/li>\n<li><strong>\u53cd\u9988<\/strong>\u7ed9\u4f60\uff0c\u81ea\u5df1\u7f51\u4e0a\u627e\u8d44\u6e90\u53bb\uff1b<\/li>\n<li>\u4f60\u53bb\u7f51\u4e0a\u627e\u8d44\u6e90\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a\u6d41\u7a0b\u5176\u5b9e\u5305\u542b\u4e86Redux\u7684\u6574\u4e2a\u6d41\u7a0b\u3002<\/p>\n<p><strong>\u8be2\u95ee + \u67e5\u9605 = \u53cd\u9988\u3002\u5373\uff1aaction + state = new state<\/strong><\/p>\n<blockquote class=\"article-blockquote\"><p><strong>\u6709\u679c\u5fc5\u6709\u56e0<\/strong><\/p><\/blockquote>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194702.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2878\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194702.png\" alt=\"20200419194702\" width=\"457\" height=\"293\"><\/a><\/div>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194725.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2879\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194725.png\" alt=\"20200419194725\" width=\"429\" height=\"278\"><\/a><\/div>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194743.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2880\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/20200419194743.png\" alt=\"20200419194743\" width=\"638\" height=\"354\"><\/a><\/div>\n<h1 class=\"pgc-h-center-line\">\u4e8c\u3001\u5177\u4f53\u7684\u6982\u5ff5<\/h1>\n<p>React-Redux \u5c06\u6240\u6709\u7ec4\u4ef6\u5206\u6210\u4e24\u5927\u7c7b\uff1aUI \u7ec4\u4ef6\uff08presentational component\uff09\u548c\u5bb9\u5668\u7ec4\u4ef6\uff08container component\uff09\u3002<\/p>\n<blockquote class=\"article-blockquote\"><p><strong>UI \u7ec4\u4ef6\u8d1f\u8d23 UI \u7684\u5448\u73b0\uff0c\u5bb9\u5668\u7ec4\u4ef6\u8d1f\u8d23\u7ba1\u7406\u6570\u636e\u548c\u903b\u8f91<\/strong><\/p><\/blockquote>\n<p>\u4f60\u53ef\u80fd\u4f1a\u95ee\uff0c\u5982\u679c\u4e00\u4e2a\u7ec4\u4ef6\u65e2\u6709 UI \u53c8\u6709\u4e1a\u52a1\u903b\u8f91\uff0c\u90a3\u600e\u4e48\u529e\uff1f\u56de\u7b54\u662f\uff0c\u5c06\u5b83\u62c6\u5206\u6210\u4e0b\u9762\u7684\u7ed3\u6784\uff1a\u5916\u9762\u662f\u4e00\u4e2a\u5bb9\u5668\u7ec4\u4ef6\uff0c\u91cc\u9762\u5305\u4e86\u4e00\u4e2aUI \u7ec4\u4ef6\u3002\u524d\u8005\u8d1f\u8d23\u4e0e\u5916\u90e8\u7684\u901a\u4fe1\uff0c\u5c06\u6570\u636e\u4f20\u7ed9\u540e\u8005\uff0c\u7531\u540e\u8005\u6e32\u67d3\u51fa\u89c6\u56fe\u3002<\/p>\n<p>React-Redux \u89c4\u5b9a\uff0c\u6240\u6709\u7684 UI \u7ec4\u4ef6\u90fd\u7531\u7528\u6237\u63d0\u4f9b\uff0c\u5bb9\u5668\u7ec4\u4ef6\u5219\u662f\u7531 React-Redux \u81ea\u52a8\u751f\u6210\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u7528\u6237\u8d1f\u8d23\u89c6\u89c9\u5c42\uff0c\u72b6\u6001\u7ba1\u7406\u5219\u662f\u5168\u90e8\u4ea4\u7ed9\u5b83\u3002<\/p>\n<p>\u4ee5\u4e0a\u6458\u5f55\u81ea&#8212;\u962e\u4e00\u5cf0\u7684\u7f51\u7edc\u65e5\u5fd7\uff0c\u5efa\u8bae\u521d\u5b66\u8005\u591a\u8bfb\u51e0\u904d\u3002<\/p>\n<ul class=\"\">\n<li><strong>Action\uff1a<\/strong>&nbsp;\u628a\u6570\u636e\u4ece\u5e94\u7528\u4f20\u5230 store \u7684\u6709\u6548\u8f7d\u8377\uff1b<\/li>\n<li><strong>Store<\/strong>: \u4fdd\u5b58\u6570\u636e\u7684\u5730\u65b9\uff1b<\/li>\n<li><strong>Dispatcher<\/strong>: view\u53d1\u51faAction\u7684\u552f\u4e00\u529e\u6cd5\uff1b<\/li>\n<li><strong>Reducer\uff1a<\/strong>&nbsp;Store\u6536\u5230Action\u4ee5\u540e\uff0c\u5fc5\u987b\u7ed9\u51fa\u4e00\u4e2a\u65b0\u7684state\uff0c\u8fd9\u6837view\u624d\u4f1a\u53d1\u751f\u53d8\u5316\u3002<strong>Reducer\u5373\u6839\u636eAction\u8ba1\u7b97state\uff1b<\/strong><\/li>\n<li><strong>State<\/strong>: store\u91cc\u9762\u5b58\u50a8\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419195109.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2884\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419195109.png\" alt=\"QQ\u255c\u256a\u2550\u255d20200419195109\" width=\"575\" height=\"438\"><\/a><\/p>\n<div class=\"pgc-img\"><\/div>\n<div class=\"pgc-img\"><\/div>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419194929.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2881\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419194929.png\" alt=\"QQ\u255c\u256a\u2550\u255d20200419194929\" width=\"633\" height=\"519\"><\/a><\/div>\n<div class=\"pgc-img\"><\/div>\n<div class=\"pgc-img\"><\/div>\n<h1 class=\"pgc-h-center-line\">\u4e09\u3001\u793a\u4f8b\u4ee3\u7801<\/h1>\n<p>Redux\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u6570\u64cd\u4f5c\uff0c\u6d89\u53ca\u5b8c\u6574\u7684\u6d41\u7a0b\u3002<\/p>\n<p>\u5176\u4e2d\u6d89\u53ca<\/p>\n<ul class=\"\">\n<li>redux\u5404\u4e2a\u6982\u5ff5\uff1b<\/li>\n<li>UI\u7ec4\u4ef6 &amp; \u5bb9\u5668\u7ec4\u4ef6 \u7684\u76f8\u4e92\u5173\u7cfb\uff1b<\/li>\n<li>Provider\u7684\u4f7f\u7528<\/li>\n<\/ul>\n<pre><code class=\"language-js\" lang=\"js\">import React, { Component } from \"react\";\nimport PropTypes from \"prop-types\";\nimport ReactDOM from \"react-dom\";\nimport { createStore } from \"redux\";\nimport { Provider, connect } from \"react-redux\";\n\n\/\/ \u751f\u6210\u7ec4\u4ef6\nclass Counter extends Component {\n  render() {\n    const { value, onIncreaseClick } = this.props;\n    return (\n      &lt;div&gt;\n        &lt;span&gt;{value}&lt;\/span&gt;\n        &lt;button onClick={onIncreaseClick}&gt;Increase&lt;\/button&gt;\n      &lt;\/div&gt;\n    );\n  }\n}\n\nCounter.propTypes = {\n  value: PropTypes.number.isRequired,\n  onIncreaseClick: PropTypes.func.isRequired\n};\n\n\/\/ \u5b9a\u4e49action\nconst increaseAction = { type: \"increase\" };\n\n\/**\n * Reducer\u51fd\u6570\n * @param {*} state \u9ed8\u8ba4\u503c\n * @param {*} action \u6839\u636eaction\u6765\u8ba1\u7b97state.\n *\/\nfunction counter(state = { count: 0 }, action) {\n  const count = state.count;\n  switch (action.type) {\n    case \"increase\":\n      return { count: count + 1 };\n    default:\n      return state;\n  }\n}\n\n\/**\n * \u521b\u5efastore -&gt; \u9700\u8981reducer -&gt; \u9ed8\u8ba4\u503c+action\n *\/\nconst store = createStore(counter);\n\n\/**\n * \u5efa\u7acb\u4e00\u4e2a\u4ece\uff08\u5916\u90e8\u7684\uff09state\u5bf9\u8c61\u5230\uff08UI \u7ec4\u4ef6\u7684\uff09props\u5bf9\u8c61\u7684\u6620\u5c04\u5173\u7cfb\u3002\n * @param {*} state\n *\/\nfunction mapStateToProps(state) {\n  return {\n    value: state.count\n  };\n}\n\n\/**\n * \u5efa\u7acb UI \u7ec4\u4ef6\u7684\u53c2\u6570\u5230store.dispatch\u65b9\u6cd5\u7684\u6620\u5c04\n * \u5b9a\u4e49\u4e86\u54ea\u4e9b\u7528\u6237\u7684\u64cd\u4f5c\u5e94\u8be5\u5f53\u4f5c Action\uff0c\u4f20\u7ed9 Store\u3002\n * \u5b83\u53ef\u4ee5\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\n *\n * 1. \u51fd\u6570\uff1a\n *      - \u53c2\u6570\uff1a\n *        \u53ef\u4ee5\u62ff\u5230dispatch\u548cownProps\uff08\u5bb9\u5668\u7ec4\u4ef6\u7684props\u5bf9\u8c61\uff09\u4e24\u4e2a\u53c2\u6570\uff1b\n *      - \u8fd4\u56de\u503c\n *        \u4e00\u4e2a\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u952e\u503c\u5bf9\u90fd\u662f\u4e00\u4e2a\u6620\u5c04\uff0c[\u952e\u540d\u5bf9\u5e94\u51fd\u6570\u540d]\n *         \u5b9a\u4e49\u4e86 UI \u7ec4\u4ef6\u7684\u53c2\u6570\u600e\u6837\u53d1\u51fa Action\u3002\n * 2. \u5bf9\u8c61\n *      \u5b83\u7684\u6bcf\u4e2a\u952e\u540d\u4e5f\u662f\u5bf9\u5e94 UI \u7ec4\u4ef6\u7684\u540c\u540d\u53c2\u6570\uff0c\u952e\u503c\u5e94\u8be5\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\n *      \u4f1a\u88ab\u5f53\u4f5c Action creator \uff0c\u8fd4\u56de\u7684 Action \u4f1a\u7531 Redux \u81ea\u52a8\u53d1\u51fa\u3002\n * @param {*} dispatch\n *\/\nfunction mapDispatchToProps(dispatch) {\n  return {\n    \/\/ \u540c\u540d\u51fd\u6570 onIncreaseClick\uff0c dispatch \u4e00\u4e2aaction\n    onIncreaseClick: () =&gt; dispatch(increaseAction)\n  };\n}\n\n\/**\n * connect \u81ea\u52a8\u751f\u6210\u5bb9\u5668\u7ec4\u4ef6\uff0c\u5c06UI\u7ec4\u4ef6[Counter]\u4e0e[\u5bb9\u5668\u7ec4\u4ef6]\u5373\u5173\u8054\u8d77\u6765\u3002\n * Counter: UI \u7ec4\u4ef6\n * mapStateToProps\uff1a \u8f93\u5165\u903b\u8f91\uff1a\u5916\u90e8\u7684\u6570\u636e\uff08\u5373state\u5bf9\u8c61\uff09\u5982\u4f55\u8f6c\u6362\u4e3a UI \u7ec4\u4ef6\u7684\u53c2\u6570\n * mapDispatchToProps\uff1a \u7528\u6237\u53d1\u51fa\u7684\u52a8\u4f5c\u5982\u4f55\u53d8\u4e3a Action \u5bf9\u8c61\uff0c\u4ece UI \u7ec4\u4ef6\u4f20\u51fa\u53bb\u3002\n *\/\nconst App = connect(\n  mapStateToProps,\n  mapDispatchToProps\n)(Counter);\n\n\/\/ React-Redux \u63d0\u4f9bProvider\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8ba9\u5bb9\u5668\u7ec4\u4ef6\u62ff\u5230state\u3002\n\/\/ Provider\u5728\u6839\u7ec4\u4ef6\u5916\u9762\u5305\u4e86\u4e00\u5c42\uff0c\u8fd9\u6837\u4e00\u6765\uff0cApp\u7684\u6240\u6709\u5b50\u7ec4\u4ef6\u5c31\u9ed8\u8ba4\u90fd\u53ef\u4ee5\u62ff\u5230state\u4e86\n\/\/ \u539f\u7406\uff1a React\u4e2d\u7684context\u5c5e\u6027\uff0c\nReactDOM.render(\n  &lt;Provider store={store}&gt;\n    &lt;App \/&gt;\n  &lt;\/Provider&gt;,\n  document.getElementById(\"root\")\n);\n<\/code><\/pre>\n<p>\u7ed3\u5408\u4e0b\u56fe\u7406\u89e3<\/p>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419194948.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2882\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419194948.png\" alt=\"QQ\u255c\u256a\u2550\u255d20200419194948\" width=\"624\" height=\"601\"><\/a><\/div>\n<p>\u56fe\u7247\u6765\u6e90\uff1ahttps:\/\/juejin.im\/post\/5acdbe8f51882548fe4a7af1<\/p>\n<h1 class=\"pgc-h-center-line\">\u603b\u7ed3<\/h1>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6700\u5916\u5c42\u7684Provider\u5229\u7528react-redux\u4e2d\u7684provider\u7ec4\u4ef6\uff0c<strong>\u90a3\u4e48\u7a76\u7adfprovider\u7ec4\u4ef6\u505a\u4e86\u4ec0\u4e48\uff1f\u4e3a\u4f55provider\u5b50\u7ec4\u4ef6\u80fd\u591f\u6216\u8bb8context\u5c5e\u6027\uff1f<\/strong><\/p>\n<blockquote class=\"article-blockquote\"><p>\u4e0a\u7bc7\u6587\u7ae0\u5229\u7528context\u8fdb\u884c\u4f20\u503c\uff0c\u5e76\u672a\u8fc7\u591a\u7684\u89e3\u91ca\u8bf4\u660e\u3002<\/p><\/blockquote>\n<p>Provider \u672c\u8eab\u662f\u4e00\u4e2a react \u7ec4\u4ef6\uff0c\u8fd9\u4e00\u70b9\u9996\u5148\u8981\u641e\u6e05\u695a\u3002\u5b83\u7684\u5b9e\u73b0\u539f\u7406\u975e\u5e38\u7b80\u5355\uff0c\u5229\u7528\u4e86 React \u7684 context \u8fd9\u4e00\u7279\u6027\u3002\u6587\u6863Context &#8211; React, \u53ea\u8981\u5728\u6700\u5916\u5c42\u7684\u7ec4\u4ef6\u5b9e\u73b0\u4e00\u4e2a getChildContext \u8fd9\u4e2a\u65b9\u6cd5\uff0c\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5185\u90e8\u7684\u7ec4\u4ef6\u90fd\u53ef\u4ee5\u901a\u8fc7 this.context \u62ff\u5230\u8fd9\u4e2a\u5bf9\u8c61\u3002\u6240\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684 Provider \u5b9e\u73b0\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code class=\"language-js\" lang=\"js\">class Provider extends React.Component {\n  getChildContext() {\n    return { store: this.props.store }    \n  }\n\n  render() {\n    return this.props.children\n  }\n}\n\n\/\/ usage\nconst store = createStore();\nReactDOM.render(\n  &lt;Provider store={store}&gt;\n    &lt;App \/&gt;\n  &lt;\/Provider&gt;\n, document.querySelector('#root'));<\/code><\/pre>\n<p>\u90a3\u4e48\u6574\u4e2a\u9875\u9762\u7684\u903b\u8f91\u6d41\u7a0b\u5c31\u662f\uff1a<\/p>\n<ol start=\"1\">\n<li>\u521b\u5efaStore\uff0ccreateStore(), \u63a5\u53d7reducers&amp;\u9ed8\u8ba4\u503c\uff1b<\/li>\n<li>createStore \u5bf9\u6bcf\u4e00\u4e2areducer\u8fdb\u884cdispatch\u4e00\u4e2aaction.type=@@redux\/INTT\u7c7b\u578b\u7684action\uff0c\u7136\u540e\u8fd4\u56destate\u9ed8\u8ba4\u503c\uff1b<\/li>\n<li>render()\u8fdb\u884c\u6e32\u67d3\uff0c\u6bcf\u4e2a\u5b50\u7ec4\u4ef6\u901a\u8fc7\u4f20\u5165\u7684this.context.store.getState()\u65b9\u6cd5\u83b7\u53d6state\u5bf9\u8c61+ownProps\u7ed9mapStateToProps\u65b9\u6cd5\uff0c\u6784\u5efaprops\uff0c\u5e94\u7528\u5230\u5b50\u7ec4\u4ef6\u4e0a\uff1b<\/li>\n<li>UI\u7ec4\u4ef6\u89e6\u53d1action, \u968f\u5373mapDispatchToProps\u89e6\u53d1\u76f8\u5e94\u7684action\uff1b<\/li>\n<li>strore\u63a5\u6536\u5230action\u8fdb\u884creduce\uff0c\u5f97\u5230\u65b0\u7684state\uff0c\u7136\u540e\u518d\u8c03\u7528\u6240\u6709\u5b50\u7ec4\u4ef6\u7684mapDispatchToProps\u751f\u6210props.<\/li>\n<li>\u6700\u540eprovider\u8fdb\u884c\u91cd\u65b0\u6e32\u67d3\u9700\u8981\u66f4\u65b0\u7684\u7ec4\u4ef6\u3002<\/li>\n<\/ol>\n<h1 class=\"pgc-h-center-line\">\u7b2c\u4e09\u90e8\u5206<\/h1>\n<p>react-redux\u793a\u4f8b&#8211;TodoList demo<\/p>\n<p>\u8bd5\u7740\u4ece\u5934\u5230\u4f4d\u5b9e\u73b0\u4e00\u8fb9\uff0c\u4f1a\u66f4\u52a0\u6df1\u5bf9\u672c\u6587\u7684\u7406\u89e3\u3002\u9274\u4e8e\u4ee3\u7801\u592a\u591a&amp;\u4e0a\u8ff0\u7684\u7406\u89e3\uff0c\u5e94\u8be5\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u4f46\u4e0d\u8981\u773c\u9ad8\u624b\u4f4e\u3002<\/p>\n<div class=\"pgc-img\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419195003.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2883\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/QQ\u255c\u256a\u2550\u255d20200419195003.png\" alt=\"QQ\u255c\u256a\u2550\u255d20200419195003\" width=\"623\" height=\"495\"><\/a><\/div>\n<h1 class=\"pgc-h-center-line\">\u611f\u8c22<\/h1>\n<pre><code>\u4e00\u5e45\u56fe\u660e\u767dReact-Redux\u7684\u539f\u7406\n\u89e3\u6790\uff1a\u8ba9\u4f60\u5f04\u61c2redux\u539f\u7406\nhttps:\/\/www.cnblogs.com\/nayek\/p\/12369418.html\nhttps:\/\/www.processon.com\/view\/5db55958e4b0e433944fdc87\nhttps:\/\/www.ruanyifeng.com\/blog\/2016\/09\/redux_tutorial_part_three_react-redux.html\n\n<a href=\"https:\/\/www.toutiao.com\/a6808016650248389131\/?tt_from=mobile_qq&amp;utm_campaign=client_share&amp;timestamp=1585123799&amp;app=news_article&amp;utm_source=mobile_qq&amp;utm_medium=toutiao_android&amp;req_id=202003251609590100140411593203CC76&amp;group_id=6808016650248389131\">\u539f\u6587<\/a><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f React \u7ec4\u4ef6 componentDidMount \u7684\u65f6\u5019\u521d\u59cb\u5316 Model\uff0c\u5e76\u76d1\u542c Model \u7684  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[125,105],"tags":[137],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2874"}],"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=2874"}],"version-history":[{"count":5,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2874\/revisions"}],"predecessor-version":[{"id":3691,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2874\/revisions\/3691"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}