{"id":53277,"date":"2024-12-03T08:31:26","date_gmt":"2024-12-03T00:31:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53277\/"},"modified":"2024-12-03T08:31:26","modified_gmt":"2024-12-03T00:31:26","slug":"redux-%e4%b8%8e-zustand%ef%bc%9a%e7%bb%bc%e5%90%88%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53277\/","title":{"rendered":"Redux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Redux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aRedux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241128\/173279216567484f65da8d3.jpg\" class=\"aligncenter\" title=\"Redux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83\u63d2\u56fe\" alt=\"Redux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83\u63d2\u56fe\" \/><\/p>\n<h2> react \u72b6\u6001\u7ba1\u7406\u6982\u8ff0 <\/h2>\n<h3> redux\uff08\u8be6\u7ec6\u8bf4\u660e\uff09\uff1a <\/h3>\n<h4> \u5efa\u7b51\u5b66\uff1a <\/h4>\n<ul>\n<li> <strong>store<\/strong>\uff1a\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e2d\u592e\u72b6\u6001\u6301\u6709\u8005<\/li>\n<li> <strong>\u64cd\u4f5c<\/strong>\uff1a\u72b6\u6001\u66f4\u6539\u7684\u4e8b\u4ef6<\/li>\n<li> <strong>reducer<\/strong>\uff1a\u521b\u5efa\u65b0\u72b6\u6001\u7684\u7eaf\u51fd\u6570<\/li>\n<\/ul>\n<h4> \u590d\u6742\uff1a <\/h4>\n<ul>\n<li>\u91cd\u8981\u7684\u6837\u677f\u4ee3\u7801<\/li>\n<li>\u9661\u5ced\u7684\u5b66\u4e60\u66f2\u7ebf<\/li>\n<li>\u652f\u6301 redux thunk\u3001redux saga \u7b49\u4e2d\u95f4\u4ef6<\/li>\n<li>\u4f7f\u7528 devtools \u8fdb\u884c\u5b8c\u6574\u72b6\u6001\u8ddf\u8e2a<\/li>\n<\/ul>\n<h4> \u4f7f\u7528\u6848\u4f8b\uff1a <\/h4>\n<ul>\n<li>\u5927\u578b\u4f01\u4e1a\u7ea7\u5e94\u7528<\/li>\n<li>\u590d\u6742\u7684\u72b6\u6001\u903b\u8f91<\/li>\n<li>\u5b9e\u65f6\u5e94\u7528<\/li>\n<li>\u591a\u5c42\u5e94\u7528<\/li>\n<\/ul>\n<h3> zustand\uff08\u8be6\u7ec6\u8bf4\u660e\uff09\uff1a <\/h3>\n<h4> \u5efa\u7b51\u5b66\uff1a <\/h4>\n<ul>\n<li>\u7b80\u5355\u7684\u57fa\u4e8e\u94a9\u5b50\u7684\u72b6\u6001\u7ba1\u7406<\/li>\n<li>\u6700\u4f4e\u914d\u7f6e<\/li>\n<li>\u652f\u6301\u7acb\u5373\u7a81\u53d8<\/li>\n<li>\u539f\u751f react hooks \u8bed\u6cd5<\/li>\n<\/ul>\n<h4> \u4f18\u70b9\uff1a <\/h4>\n<ul>\n<li>\u6781\u5176\u8f7b\u91cf\uff08\u4ec51.5kb\uff09<\/li>\n<li>\u9700\u8981\u7f16\u5199\u7684\u4ee3\u7801\u66f4\u5c11<\/li>\n<li>\u9ad8\u6027\u80fd<\/li>\n<li>\u7b80\u5355\u7684\u5f02\u6b65\u64cd\u4f5c<\/li>\n<\/ul>\n<h4> \u4f7f\u7528\u6848\u4f8b\uff1a <\/h4>\n<ul>\n<li>\u4e2d\u5c0f\u578b\u5e94\u7528<\/li>\n<li>\u53cd\u5e94\u9879\u76ee<\/li>\n<li>\u5feb\u901f\u539f\u578b\u5236\u4f5c<\/li>\n<li>\u7b80\u5355\u7684\u72b6\u6001\u7ba1\u7406<\/li>\n<\/ul>\n<h3> \u4ee3\u7801\u6bd4\u8f83 <\/h3>\n<h4> \u8fd8\u539f\u793a\u4f8b\uff1a <\/h4>\n<pre>\/\/ redux store\nconst initialstate = { count: 0 }\nfunction counterreducer(state = initialstate, action) {\n  switch (action.type) {\n    case 'increment':\n      return { count: state.count + 1 }\n    default:\n      return state\n  }\n}\n<\/pre>\n<h4> \u7956\u65af\u5766\u793a\u4f8b\uff1a <\/h4>\n<pre>import create from 'zustand'\n\nconst useCounterStore = create((set) =&gt; ({\n  count: 0,\n  increment: () =&gt; set((state) =&gt; ({ count: state.count + 1 }))\n}))\n<\/pre>\n<h3> \u4e3b\u8981\u533a\u522b\uff1a <\/h3>\n<ol>\n<li> <strong>redux\uff1a<\/strong>\u66f4\u591a\u63a7\u5236\uff0c\u590d\u6742<\/li>\n<li> <strong>zustand\uff1a<\/strong>\u7b80\u5355\uff0c\u4ee3\u7801\u5c11<\/li>\n<\/ol>\n<h3> \u4ec0\u4e48\u65f6\u5019\u9009\u62e9\uff1f <\/h3>\n<h4> \u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u4f7f\u7528 redux\uff1a <\/h4>\n<ul>\n<li>\u6784\u5efa\u5927\u578b\u5e94\u7528\u7a0b\u5e8f<\/li>\n<li>\u9700\u8981\u590d\u6742\u7684\u72b6\u6001\u903b\u8f91<\/li>\n<li>\u56e2\u961f\u9879\u76ee<\/li>\n<li>\u9700\u8981\u591a\u4e2a\u4e2d\u95f4\u4ef6<\/li>\n<\/ul>\n<h4> \u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u4f7f\u7528 zustand\uff1a <\/h4>\n<ul>\n<li>\u4e2d\u5c0f\u578b\u5e94\u7528<\/li>\n<li>\u7b80\u5355\u7684\u72b6\u6001\u7ba1\u7406<\/li>\n<li>\u5feb\u901f\u539f\u578b\u5236\u4f5c<\/li>\n<li>\u6240\u9700\u7684\u6700\u5c0f\u6837\u677f<\/li>\n<\/ul>\n<h3> \u7ed3\u8bba <\/h3>\n<p>\u4f5c\u4e3a\u8f6f\u4ef6\u67b6\u6784\u5e08\uff0c\u6839\u636e\u9879\u76ee\u89c4\u6a21\u548c\u590d\u6742\u6027\u9009\u62e9\u6280\u672f\u3002<\/p>\n<h3> \u6700\u4f73\u5b9e\u8df5\uff1a <\/h3>\n<ul>\n<li>\u8bc4\u4f30\u9879\u76ee\u9700\u6c42<\/li>\n<li>\u8003\u8651\u56e2\u961f\u4e13\u4e1a\u77e5\u8bc6<\/li>\n<li>\u5206\u6790\u6027\u80fd\u9700\u6c42<\/li>\n<li>\u89c4\u5212\u672a\u6765\u7684\u53ef\u6269\u5c55\u6027<\/li>\n<\/ul>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aRedux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u7535\u8111\u84dd\u5c4f\u73b0\u8c61\u8be6\u89e3\uff1a\u539f\u56e0\u3001\u89e3\u51b3\u65b9\u6848\u4e0e\u9884\u9632\u63aa\u65bd\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Redux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83 \u6536\u85cf \u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300aRedux \u4e0e Zustand\uff1a\u7efc\u5408\u6bd4\u8f83\u300b\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u6587\u7ae0\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01 react \u72b6\u6001\u7ba1\u7406\u6982\u8ff0 redux\uff08\u8be6\u7ec6\u8bf4\u660e\uff09\uff1a \u5efa\u7b51\u5b66\uff1a store\uff1a\u6574\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e2d\u592e\u72b6\u6001\u6301\u6709\u8005 \u64cd\u4f5c\uff1a\u72b6\u6001\u66f4\u6539\u7684\u4e8b\u4ef6 reducer\uff1a\u521b\u5efa\u65b0\u72b6\u6001\u7684\u7eaf\u51fd\u6570 \u590d\u6742\uff1a \u91cd\u8981\u7684\u6837\u677f\u4ee3\u7801 \u9661\u5ced\u7684\u5b66\u4e60\u66f2\u7ebf \u652f\u6301 redux thunk\u3001redux saga \u7b49\u4e2d\u95f4\u4ef6 \u4f7f\u7528 devtools \u8fdb\u884c\u5b8c\u6574\u72b6\u6001\u8ddf\u8e2a \u4f7f\u7528\u6848\u4f8b\uff1a \u5927\u578b\u4f01\u4e1a\u7ea7\u5e94\u7528 \u590d\u6742\u7684\u72b6\u6001\u903b\u8f91 \u5b9e\u65f6\u5e94\u7528 \u591a\u5c42\u5e94\u7528 zustand\uff08\u8be6\u7ec6\u8bf4\u660e\uff09\uff1a \u5efa\u7b51\u5b66\uff1a \u7b80\u5355\u7684\u57fa\u4e8e\u94a9\u5b50\u7684\u72b6\u6001\u7ba1\u7406 \u6700\u4f4e\u914d\u7f6e \u652f\u6301\u7acb\u5373\u7a81\u53d8 \u539f\u751f react hooks \u8bed\u6cd5 \u4f18\u70b9\uff1a \u6781\u5176\u8f7b\u91cf\uff08\u4ec51.5kb\uff09 \u9700\u8981\u7f16\u5199\u7684\u4ee3\u7801\u66f4\u5c11 \u9ad8\u6027\u80fd \u7b80\u5355\u7684\u5f02\u6b65\u64cd\u4f5c \u4f7f\u7528\u6848\u4f8b\uff1a \u4e2d\u5c0f\u578b\u5e94\u7528 \u53cd\u5e94\u9879\u76ee \u5feb\u901f\u539f\u578b\u5236\u4f5c \u7b80\u5355\u7684\u72b6\u6001\u7ba1\u7406 \u4ee3\u7801\u6bd4\u8f83 \u8fd8\u539f\u793a\u4f8b\uff1a \/\/ redux store const [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53277","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=53277"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53277\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}