{"id":362611,"date":"2021-02-26T19:44:06","date_gmt":"2021-02-26T11:44:06","guid":{"rendered":"http:\/\/4563.org\/?p=362611"},"modified":"2021-02-26T19:44:06","modified_gmt":"2021-02-26T11:44:06","slug":"%e6%9c%89%e5%a4%9a%e5%b0%91-react-%e9%a1%b9%e7%9b%ae%e6%98%af%e7%94%a8%e5%88%b0-redux-%e7%9a%84","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=362611","title":{"rendered":"\u6709\u591a\u5c11 React \u9879\u76ee\u662f\u7528\u5230 redux \u7684?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u591a\u5c11 React \u9879\u76ee\u662f\u7528\u5230 redux \u7684?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : maxssy <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u771f\u7684\u6709\u90a3\u4e48\u591a\u9879\u76ee\u7531\u7ec4\u4ef6\u95f4\u901a\u4fe1\u7684\u9700\u6c42\u5417? \u7528 context \u4e0d\u597d\u5417?<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5425459\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fengfuliu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             React \u9879\u76ee\u90a3\u4e48\u591a \u80af\u5b9a\u6709\u90e8\u5206\u9879\u76ee\u662f\u6bd4\u8f83\u590d\u6742\u7684\u554a \u518d\u8005\u5f53\u5f00\u53d1\u7f16\u8f91 \/\u64a4\u9500\u4e00\u4e9b\u529f\u80fd\u7684\u65f6\u5019\u4e5f\u5f88\u597d\u7528<br \/>redux \u66f4\u591a\u7684\u662f\u4e00\u79cd\u601d\u60f3 \u800c\u4e14\u7528\u8d77\u6765\u4e5f\u6ca1\u90a3\u4e48\u9ebb\u70e6 \u9ebb\u70e6\u7684\u662f\u7528\u7684\u65f6\u5019\u7528 react-redux\/redux-thunk \u90fd\u7528\u7684\u65f6\u5019\u65b0\u624b\u5bb9\u6613\u6df7\u5427 \u611f\u89c9\u9898\u4e3b\u662f\u5728\u770b\u9762\u8bd5\u8d44\u6599\u7136\u540e\u770b\u5230 redux \u76f8\u5173\u7684\u77e5\u8bc6\u70b9\u770b\u4e86\u89c9\u5f97\u590d\u6742\u7136\u540e\u6709\u8fd9\u4e2a\u95ee\u9898\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425460\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ericls <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u51e0\u5e74\u5bf9\u5b83\u7684\u9700\u6c42\u8d8a\u6765\u8d8a\u5c11 \u56e0\u4e3a\u6709\u4e86\u5185\u7f6e\u7684 reducer \u800c\u4e14 hooks \u91cc\u9762 context \u4e5f\u8d8a\u6765\u8d8a\u597d\u7528\u4e86\u3002 \u4f46\u662f\u5b83\u5bf9 react \u8fd8\u662f\u5f88\u6709\u8d21\u732e\u7684\u3002<\/p>\n<p>\u7528 context \u4f60\u9700\u8981\u6ce8\u610f\u4e00\u4e2a\u95ee\u9898 \u5982\u679c\u4f60\u7684 context \u662f\u4e2a mutable object \u53ea\u8981\u5176\u4e2d\u4e00\u4e2a value \u53d8\u4e86\u6240\u6709 consumer \u90fd\u4f1a re-render. \u8fd9\u4e2a\u65f6\u5019\u4f60\u53ef\u4ee5\u5199\u4e00\u4e9b selector \u6765\u89c4\u907f\u8fd9\u4e2a\u95ee\u9898 \u8fd9\u4e2a\u65f6\u5019\u4f60\u57fa\u672c\u4e0a\u5c31\u81ea\u5df1\u5199\u4e86\u534a\u4e2a redux \u4e86. \u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u6709\u522b\u7684\u529e\u6cd5                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425461\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : noe132 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             mobx \u4e0d\u9999\u4e48                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425462\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : PeakFish <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u597d\u591a\u5e94\u7528\uff0c\u6839\u672c\u4e0d\u9700\u8981\u90a3\u4e48\u590d\u6742\uff0c\u778e\u641e\u6574\u7684\u7f51\u7ad9 js \u5f88\u5927\uff0c\u5bf9\u6211\u6765\u8bf4 event bus \u66f4\u597d\u7528\uff0c\u51e0\u884c\u4ee3\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425463\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : love <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u7b2c\u4e00\u4e2a\u9879\u76ee\u662f\u7528 redux\uff0c\u4ee5\u540e\u53d1\u73b0\u8fd9\u5e93\u7b80\u76f4\u6709\u70b9\u53ef\u7b11\uff0c\u6539\u6570\u636e\u7ed3\u6784\u65b9\u5f0f\u592a\u539f\u59cb\u53ef\u601c\u4e86\uff0c\u540e\u6765\u7528 immer \u81ea\u5236\u4e86\u4e00\u4e2a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425464\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yyfearth <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u4e86 useContext\/useState\/useReducer \u5bf9 redux \u7684\u9700\u6c42\u51cf\u5c11\u4e86\u5f88\u591a<br \/>\u4f46\u662f\u9879\u76ee\u5df2\u7ecf\u5f00\u59cb\u51e0\u5e74\u4e86 \u800c\u4e14\u5c31\u7b97\u662f\u65b0\u9879\u76ee \u5f80\u5f80\u4e5f\u4f1a\u7528\u5c31\u9879\u76ee\u7684\u6846\u67b6<br \/>\u4e0d\u7ba1\u600e\u6837\u7a0d\u5fae\u5927\u4e00\u70b9\u7684\u9879\u76ee redux \u57fa\u672c\u4e0a\u662f\u6807\u914d \u800c\u4e14\u719f\u6089 react \u7684\u4eba\u5f80\u5f80\u90fd\u63a5\u89e6\u8fc7 redux<br \/>mobx \u76f8\u5bf9\u5c0f\u4f17\u4e00\u70b9 \u4f46\u662f\u5bf9\u4e8e TS \u7684\u9879\u76ee \u8c8c\u4f3c\u6bd4\u8f83\u6b22\u8fce                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5425465\" 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>                                                             \u786e\u5b9e\u6ca1\u6709\u5fc5\u8981\uff0c\u800c\u4e14\u6211\u770b\u5927\u5bb6\u7528 redex \u90fd\u662f\u7528\u6765\u53d1 effect,\u62c9\u63a5\u53e3\u5565\u7684\uff0c\u9664\u975e\u4f60\u4eec\u4e00\u5b9a\u8981\u4e0a ssr\uff0c\u5426\u5219\u6ca1\u6709\u5fc5\u8981\uff0c\u5e26\u6765\u7684\u95ee\u9898\u6bd4\u4e0d\u7528 redux \u7684\u591a\u3002<br \/>\u6211\u8ba4\u4e3a\u4e00\u822c\u8981\u7528 redux \u662f\u590d\u6742\u573a\u666f\uff0c\u9700\u8981\u7528\u5230\u72b6\u6001\u56de\u6eaf\u5b9a\u4f4d\u95ee\u9898\u7684\u90a3\u6837\uff0c\u4e5f\u5c31\u662f\u8bf4\u6ca1\u6709\u7528 redux dev-tool \u4e5f\u5c31\u767d\u7528\u4e86\u3002\u6211\u4eec\u4e00\u822c\u505a\u4e1a\u52a1\u7c7b\u9879\u76ee\u7684\uff0c\u4f60\u8bf4\u5b83\u5927\u5427\uff0c\u4e5f\u633a\u5927\uff0c\u590d\u6742\u5374\u6ca1\u6709\uff0c\u4e5f\u5c31\u662f\u9875\u9762\u591a\u4e00\u70b9\u3002\u8fd9\u6837\u7cfb\u7edf\u9700\u8981\u5b58\u5168\u5c40\u53ea\u6709\u7528\u6237\u4fe1\u606f\u548c\u7cfb\u7edf\u914d\u7f6e\u7c7b\u7684\u6570\u636e\uff0c \u518d\u52a0\u4e0a\u73b0\u5728 hooks \u4e5f\u4e00\u5806\u7684 swr \u7684\u65b9\u6848\uff0c\u62c9\u6570\u636e\u6bd4 redux \u4e4b\u7c7b\u7684\u5168\u5c40\u597d\u592a\u591a\u3002<br \/>\u6211\u4e2a\u4eba\u8ba4\u4e3a\u590d\u6742\u573a\u666f\u662f\u505a\u7f16\u8f91\u5668\uff0c\u6bd4\u5982\u6574\u4e2a\u601d\u7ef4\u5bfc\u56fe\uff0clow code \u7f16\u8f91\u5668\uff0c\u8fd9\u6837\u662f\u4e00\u5b9a\u8981\u4e0a redux, \u6ca1\u6709\u72b6\u6001\u56de\u6eaf\u5b8c\u5168\u4e0d\u80fd\u7528\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u591a\u5c11 React \u9879\u76ee\u662f\u7528\u5230 r&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\/362611"}],"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=362611"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/362611\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362611"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}