{"id":199770,"date":"2020-11-07T20:06:29","date_gmt":"2020-11-07T12:06:29","guid":{"rendered":"http:\/\/4563.org\/?p=199770"},"modified":"2020-11-07T20:06:29","modified_gmt":"2020-11-07T12:06:29","slug":"react-redux-%e6%98%af%e6%8e%a8%e8%8d%90%e7%94%a8%e4%bc%a0%e7%bb%9f%e7%9a%84%e7%88%b7%e7%88%b6%e5%ad%90%e4%bc%a0%e5%8f%82%e6%96%b9%e5%bc%8f%ef%bc%8c%e8%bf%98%e6%98%af-hooks-%e7%9a%84%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=199770","title":{"rendered":"react-redux \u662f\u63a8\u8350\u7528\u4f20\u7edf\u7684\u7237\u7236\u5b50\u4f20\u53c2\u65b9\u5f0f\uff0c\u8fd8\u662f hooks \u7684\u65b9\u5f0f\u53d1\u9001 acton\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  react-redux \u662f\u63a8\u8350\u7528\u4f20\u7edf\u7684\u7237\u7236\u5b50\u4f20\u53c2\u65b9\u5f0f\uff0c\u8fd8\u662f hooks \u7684\u65b9\u5f0f\u53d1\u9001 acton\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u516c\u53f8\u7684\u9879\u76ee\uff0creact, redux, + saga \u7684\uff0c\u4e09\u56db\u5e74\u4e86\u3002\u4eca\u5e74\uff0c\u5f00\u59cb\uff0c\u5347\u7ea7\u4e86 react \u7684\u7248\u672c\uff0c\u6709\u4eba\u5f00\u59cb\u7528 hooks \u4e86\u3002<\/p>\n<p>\u4e8e\u662f\u6211\u4e5f\u8ddf\u98ce\u7528 hooks\uff0c\u5c24\u5176\u662f useDispatch \u3002 \u8fd9\u6837\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u6bd4\u8f83\u7b80\u5355\u7684\u7ec4\u4ef6\uff0c\u53ea\u53d1\u9001\u4e00\u4e9b\u6bd4\u8f83\u7b80\u5355\u7684 action\uff0c\u6211\u4e0d\u7528\u5728 props \u91cc\u9762\u5b9a\u4e49\u4e00\u5806 functions\uff0c\u7136\u540e\u901a\u8fc7 \u7956\u5b97\uff0c\u592a\u7237\u7237\uff0c\u7237\u7237\uff0c\u7236\u4eb2\u628a \u5177\u4f53\u7684\u7528\u6237\u51fd\u6570\u4f20\u9012\u8fdb\u6765\u3002\u53ef\u4ee5\u76f4\u63a5\u5728\u5f53\u524d\u7ec4\u4ef6\u91cc\u9762\uff0c\u5c31\u76f4\u63a5\u53d1\u9001 actions \u4e86\u3002<\/p>\n<p>\u7ed3\u679c\uff0c\u5728\u4ee3\u7801\u5ba1\u67e5\u65f6\uff0c\u6709\u4e2a\u4eba\u52a0\u6ce8\u91ca\u8bf4\uff0c\u8ba9\u6211\u4e0d\u8981\u7528 useDispatch\uff0c\u6539\u56de\u4f20\u7edf\u7684 react-redux \u65b9\u5f0f\u3002<\/p>\n<p>\u6211\u7279\u610f\u53bb google \u641c\u7d22\u4e86\u4e00\u4e0b\uff0c\u6ca1\u6709\u627e\u5230\u76f8\u5173\u7684\u8ba8\u8bba\u3002\u5728\u7ec4\u4ef6\u5185\uff0c\u76f4\u63a5\u4f7f\u7528 useDispatch\uff0c\u7136\u540e\u53d1\u9001 actions \u7684\u65b9\u6cd5\uff0c\u4e0d\u63a8\u8350\u4e48\uff1f<\/p>\n<p>\u6211\u7684\u7406\u89e3\u662f\uff0chooks \u8fd9\u4e00\u5957\uff0c\u5c31\u662f\u4e3a\u4e86\u7b80\u5316 \/\u4f18\u5316\u4e00\u4e9b\u590d\u6742\u5197\u4f59\u7684\u8c03\u7528\u3002\u4e3a\u5565\u8fd9\u4e2a\u4e0d\u63a8\u8350\u7528\uff1f\u662f\u6709\u4ec0\u4e48\u8bf4\u6cd5\u4e48\uff1f<\/p>\n<p>\u60f3\u6765\u542c\u542c\u5927\u5bb6\u7684\u610f\u89c1<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>17<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4264249\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liubiantao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53c2\u8003\u5b98\u65b9\u6307\u5357 [Style Guide | Redux]( https:\/\/redux.js.org\/style-guide\/style-guide#use-the-react-redux-hooks-api )                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264250\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gouflv <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8ddf redux \u8bf4\u518d\u89c1\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264251\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tonyYo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u82b1\u4e86\u5927\u529b\u6c14\u5f03\u7528\u4e86 redux                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264252\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : yazoox <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @gouflv \u8fd9\u4e2a\uff0c\u771f\u7684\u653e\u5f03\u4e0d\u4e86\u554a\u3002\u4ee5\u524d\u7684\u90a3\u5957\u6846\u67b6\uff0c\u5199\u4e86\u597d\u591a\u4ee3\u7801\u3002\u9876\u591a\u53ea\u80fd\u65b0\u4ee3\u7801\u6539\u8fdb\u4e00\u4e0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264253\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : joesonw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7237\u7236\u5b50\u4f20\u9012\u7684\u8bdd\u8fd8\u7528\u4ec0\u4e48 redux \u554a.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264254\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zqx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 React \u7684 Context API \u7b80\u5355\u4e00\u4e9b\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264255\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : baxtergu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u90fd\u7528 saga \u4e86\u5c31\u8fd8\u662f\u6309\u7167 saga \u90a3\u5957\u4e2d\u5fc3\u5316 store \u7684\u6a21\u5f0f\u6765\u5427\u3002\u5982\u679c\u60f3\u5728\u7ec4\u4ef6\u5185\u4f7f\u7528 hooks\uff0c\u90a3\u5c31\u5728\u4f60\u7684\u9875\u9762\u6700\u5916\u5c42\u5305\u4e00\u5c42 conncect \u628a dispatch \u548c store \u4f20\u8fdb\u53bb\uff08\u53ef\u4ee5\u7237\u7236\u5b50\u4e00\u5c42\u4e00\u5c42\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a context \u76f4\u63a5\u9694\u7740\u4f20\u4e0b\u53bb\uff09\uff0c\u91cc\u9762\u7684\u6d88\u8d39\u7ec4\u4ef6\u53ea\u8981\u5199\u597d effect \u5904\u7406\u597d\u5f15\u7528\u53d8\u66f4\u5c31\u597d\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264256\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KuroNekoFan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u53cd\u6b63\u633a\u8ba8\u538c\u90a3\u79cd\u4e00\u677f\u4e00\u773c\u7684\u5199\u6cd5\u7684\uff0c\u6709\u7684\u4eba\u559c\u6b22<br \/>\u53ea\u80fd\u6253\u4e00\u67b6\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264257\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : KuroNekoFan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f46\u662f\u8ba9\u4e0d\u8981\u7528 useDispatch \u660e\u663e\u5c31\u6709\u95ee\u9898\u4e86\uff0chooks \u51fa\u73b0\u7684\u5176\u4e2d\u4e00\u4e2a\u539f\u56e0\u5c31\u662f\u4e3a\u4e86\u8ba9\u4eba\u89c4\u907f connect \u8fd9\u79cd hoc                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264258\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dartabe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u522b\u7528 HOC \u4f60\u6bcf\u4e2a\u6a21\u5757\u8fd8\u8981\u5199\u4e2a\u8fde\u63a5\u5b8c\u5168\u662f\u6d6a\u8d39\u65f6\u95f4 <\/p>\n<p>\u5f53\u7136\u53ea\u662f\u6211\u7684\u4e2a\u4eba\u770b\u6cd5 \u5e0c\u671b\u6709\u5927\u4f6c\u6765\u8bf4\u8bf4                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264259\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : duan602728596 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u5565\u8bf4\u6cd5\uff0c\u63a8\u8350\u4f7f\u7528 useDispatch                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264260\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : matatabi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u76f4\u5728\u7528 dva,hooks \u8fd8\u6ca1\u6709\u7528\u4e0a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264261\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nav4e <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u8d77\u6765\u4e3b\u8981\u8fd8\u662f\u4e3a\u4e86\u533a\u5206 Container \u548c Presentational \u7ec4\u4ef6<\/p>\n<p>\u5c55\u793a\u7ec4\u4ef6\u4e0d\u76f4\u63a5\u4f7f\u7528\u5230 dispatch, \u53ea\u54cd\u5e94 props \u884c\u4e3a\uff0c \u5728\u4ee3\u7801\u5927\u6539\u52a8\u7684\u65f6\u5019\uff0c \u53ea\u9700\u8981\u52a8\u5230 Container<br \/>https:\/\/medium.com\/@dan_abramov\/smart-and-dumb-components-7ca2f9a7c7d0<\/p>\n<p>\u5982\u679c\u662f\u51fa\u73b0\u4f20\u9012\u5c42\u7ea7\u592a\u6df1, \u5efa\u8bae\u5b9a\u597d context \u7684 api\uff0c \u8d70 context                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : VDimos <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90fd\u7528\u8fc7\uff0c\u8fd8\u662f\u56de\u5230 context \u4e86\uff0ccontext \u6c38\u8fdc\u7684\u795e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : connection <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 redux \u7684\u4e00\u4e2a\u597d\u5904\u5c31\u662f\u89c4\u907f\u591a\u5c42\u7ea7\u4f20\u9012\u65e0\u7528 props \u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : weixiangzhe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             redux \u4e3b\u8981\u8fd8\u662f\u5168\u5c40\u72b6\u6001\uff0c\u6211\u770b\u5f88\u591a\u4eba\u7684\u65f6\u5019\uff0c\u7279\u522b\u662f\u914d\u5408 dva \u7528\u7684\u65f6\u5019\uff0credux \u53ea\u505a\u6570\u636e\u8f7d\u5165\u7528\u3002\u6211\u8fd9\u4e2a\u6709\u4e2a\u8001\u9879\u76ee\u7528\u6237\u6570\u636e\u901a\u8fc7 localStorage \u5b58\uff0c\u6240\u6709\u63a5\u53e3\u90fd\u662f redux \u8d70\uff0c\u5934\u5927\u7684\u5f88\u3002\u5b9e\u9645\u4e0a\u5927\u90e8\u5206\u65f6\u5019\u786e\u5b9e\u4e0d\u9700\u8981 redux, \u5f53\u524d\u6211\u4eec\u8fd9\u8fb9\u7528 redux \u6216\u8005\u5168\u5c40\u72b6\u6001\u7684\u60c5\u666f\uff1a<\/p>\n<p>\u7cfb\u7edf\u7ea7\u9700\u8981\u7528\u7684\u6570\u636e\uff0c\u7528\u6237\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u7cfb\u7edf\u914d\u7f6e\uff0cws \u4f20\u8fc7\u6765\u7684\u6570\u636e\uff1b                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4264265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Qinmei <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             redux \u7684 useSelector \u4ee5\u53ca useDispatch \u5c31\u662f\u7ed9 hook \u7528\u7684\uff0c\u5982\u679c\u4f60\u7528 hooks \u8fd8\u8981\u5148 connect\uff0c\u90a3\u76f8\u5f53\u4e8e\u4e0d\u7528\u554a<\/p>\n<p>\u5982\u679c\u8bf4\u76f4\u63a5\u7528\u8ddf\u4e1a\u52a1\u4e0d\u592a\u5339\u914d\uff0c\u90a3\u4e5f\u53ef\u4ee5\u81ea\u884c\u5c01\u88c5\u4e00\u5957\uff0credux \u53ea\u662f\u4e00\u79cd\u601d\u60f3\u8303\u5f0f\uff0c\u5982\u679c\u8fde\u4ee3\u7801\u90fd\u8981\u6837\u677f\u5316\uff0c\u90a3\u624d\u662f\u771f\u7684\u9650\u5236\u6b7b\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>react-redux \u662f\u63a8\u8350\u7528\u4f20&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/199770"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=199770"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/199770\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=199770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=199770"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=199770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}