{"id":4106,"date":"2024-11-10T15:08:58","date_gmt":"2024-11-10T07:08:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4106\/"},"modified":"2024-11-10T15:08:58","modified_gmt":"2024-11-10T07:08:58","slug":"%e5%bc%ba%e5%8c%96%e5%9b%bd%e5%ae%b6%e6%a3%ae%e6%9e%97%e7%9a%84%e6%83%85%e8%8a%82","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4106\/","title":{"rendered":"\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797\u7684\u60c5\u8282"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173122597664502.jpg\" class=\"aligncenter\" title=\"\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797\u7684\u60c5\u8282\u63d2\u56fe\" alt=\"\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797\u7684\u60c5\u8282\u63d2\u56fe\" \/><\/p>\n<h3> <strong>\u7b2c\u4e8c\u96c6\uff1a\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797<\/strong> <\/h3>\n<hr>\n<p>\u963f\u6797\u5728\u6cd5\u5178\u80fd\u91cf\u5728\u5468\u56f4\u6d41\u52a8\u7684\u7a33\u5b9a\u55e1\u55e1\u58f0\u4e2d\u9192\u6765\uff0c<strong>\u53cd\u5e94\u5143\u7d20<\/strong>\u7684\u751f\u52a8\u5149\u8292\u7167\u4eae\u4e86\u56fd\u5bb6\u68ee\u6797\u3002\u4eca\u5929\u662f\u5979\u52a0\u5165<strong>\u884c\u661f\u9632\u5fa1\u519b\u56e2\uff08pdc\uff09<\/strong>\u4ee5\u6765\u7684\u7b2c\u4e00\u4e2a\u91cd\u5927\u4efb\u52a1 &#8211; \u5979\u5f88\u7d27\u5f20\u3002\u5979\u88ab\u6307\u6d3e\u4e0e<strong>\u56fd\u5bb6\u5b88\u62a4\u8005<\/strong>\u4e00\u8d77\u8bad\u7ec3\uff0c\u4ed6\u4eec\u662fcodex\u6570\u636e\u7ba1\u7406\u7cfb\u7edf\u7684\u4fdd\u62a4\u8005\uff0c\u8d1f\u8d23\u4fdd\u6301\u80fd\u91cf\u6d41\u52a8\u987a\u7545\u5e76\u786e\u4fdd\u7528\u6237\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<p>\u201c\u5b66\u5458\u963f\u6797\uff0c\u51c6\u5907\u597d\u7b2c\u4e00\u6b21\u771f\u6b63\u7684\u91ce\u5916\u6f14\u4e60\u4e86\u5417\uff1f\u201d\u558a\u51fa\u4e86\u5979\u5f53\u5929\u7684\u8bad\u7ec3\u5e08<strong>stateflow\u4e2d\u5c09<\/strong>\u3002\u4e2d\u5c09\u662f\u5b88\u62a4\u8005\u4e2d\u7684\u4e00\u4f4d\u4ee4\u4eba\u656c\u754f\u7684\u4eba\u7269\uff0c\u4ee5\u5176\u7cbe\u5fc3\u7ec4\u7ec7\u56fd\u5bb6\u68ee\u6797\u7684\u65b9\u5f0f\u800c\u95fb\u540d\uff0c\u56fd\u5bb6\u68ee\u6797\u662f\u6cd5\u5178\u7684\u6838\u5fc3\uff0c\u6570\u636e\u5728\u8fd9\u91cc\u6536\u96c6\u3001\u7ef4\u62a4\u548c\u53d1\u9001\u3002<\/p>\n<p>\u963f\u7433\u70b9\u70b9\u5934\uff0c\u611f\u53d7\u5230\u5979\u7684\u4efb\u52a1\u7684\u5206\u91cf\u3002\u5979\u4e0d\u518d\u53ea\u662f\u7ec3\u4e60\u2014\u2014\u6bcf\u4e00\u4e2a\u52a8\u4f5c\u90fd\u5f88\u91cd\u8981\u3002<\/p>\n<hr>\n<p><strong>\u201c\u72b6\u6001\u89e3\u5256\u201d<\/strong><\/p>\n<p>stateflow\u4e2d\u5c09\u5e26\u9886arin\u7a7f\u8fc7\u8302\u5bc6\u7684\u68ee\u6797\uff0c\u4ed6\u7684\u5b58\u5728\u5728\u5145\u6ee1\u6d3b\u529b\u3001\u8109\u52a8\u7684\u53cd\u5e94\u5143\u7d20\u67f1\u82e5\u9690\u82e5\u73b0\u7684\u4e2d\u95f4\u5e73\u9759\u4e0b\u6765\u3002 \u201c\u56fd\u5bb6\u68ee\u6797\u662f\u6cd5\u5178\u5f97\u4ee5\u751f\u5b58\u7684\u52a8\u529b\uff0c\u201d\u4ed6\u6307\u7740\u5468\u56f4\u4e0d\u540c\u65b9\u5411\u6d41\u52a8\u7684\u8bb8\u591a\u80fd\u91cf\u8109\u7edc\u8bf4\u9053\u3002 \u201c\u4fdd\u6301\u5e73\u8861\u7684\u5173\u952e\u662f\u4e86\u89e3\u4f55\u65f6\u521b\u5efa\u3001\u63d0\u5347\u548c\u5171\u4eab\u72b6\u6001\u3002\u5982\u679c\u51fa\u9519\uff0c\u6574\u4e2a\u6d41\u7a0b\u53ef\u80fd\u4f1a\u4e0d\u7a33\u5b9a\u3002\u201d<\/p>\n<p>arin \u8bb0\u5f97\u6628\u5929\u5c0f\u51b2\u7a81\u7684\u6df7\u4e71\u2014\u2014\u90a3\u4e9b\u65e0\u5e8f\u7684 bug \u4e0d\u53ef\u9884\u6d4b\u5730\u4f20\u64ad\uff0c\u5c31\u50cf\u65e9\u671f\u751f\u547d\u5468\u671f\u4e8b\u6545\u4e2d\u7684<strong>\u4ea7\u54c1\u6a21\u5757<\/strong>\u3002\u56fd\u5bb6\u662f\u6cd5\u5178\u529b\u91cf\u7684\u6838\u5fc3\uff0c\u6ee5\u7528\u5b83\u5c06\u610f\u5473\u7740\u50cf\u5979\u4eb2\u773c\u76ee\u7779\u7684\u90a3\u6837\u7684\u6df7\u4e71\u3002<\/p>\n<p><strong>\u201c\u72b6\u6001\u63d0\u5347\u201d<\/strong><\/p>\n<p>stateflow\u4e2d\u5c09\u505c\u5728\u4e00\u4e2a\u53d1\u5149\u7684\u661f\u56e2\u524d\uff0creactium\u80fd\u91cf\u4ee5\u96c6\u4e2d\u7684\u65b9\u5f0f\u6d41\u52a8\u3002 \u201c\u8fd9\u91cc\u7684\u8fd9\u4e2a\u96c6\u7fa4\uff0c\u201d\u4ed6\u6307\u7740\u8bf4\u9053\uff0c\u201c\u4ee3\u8868\u5171\u4eab\u72b6\u6001\u3002\u9762\u4e34\u7684\u6311\u6218\u662f\u51b3\u5b9a\u5982\u4f55\u7ba1\u7406\u548c\u63d0\u5347\u8fd9\u79cd\u80fd\u91cf\uff0c\u786e\u4fdd\u5b83\u6709\u5229\u4e8e\u6240\u6709\u5468\u56f4\u7684\u7ec4\u4ef6\uff0c\u800c\u4e0d\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u538b\u529b\u3002\u201d<\/p>\n<p>\u4ed6\u7ee7\u7eed\u8bf4\u9053\uff0c\u201c\u8bb8\u591a\u5b66\u5458\u72af\u4e86\u5c06\u72b6\u6001\u4fdd\u6301\u5f97\u592a\u6df1\u7684\u9519\u8bef &#8211; \u57cb\u85cf\u5728\u53ef\u80fd\u9700\u8981\u5171\u4eab\u5b83\u7684\u7ec4\u4ef6\u4e2d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u63d0\u5347\u72b6\u6001\uff0c\u4f7f\u5176\u8fbe\u5230\u53ef\u4ee5\u6d41\u5411\u6bcf\u4e2a\u9700\u8981\u5b83\u7684\u90e8\u5206\u7684\u6c34\u5e73\u3002\u201d<\/p>\n<p>arin \u770b\u7740 stateflow \u5de7\u5999\u5730\u64cd\u7eb5 reactium \u6d41\uff0c\u5c06\u5176\u5411\u4e0a\u5f15\u5bfc\uff0c\u5141\u8bb8\u591a\u4e2a\u5206\u652f\u540c\u65f6\u8bbf\u95ee\u5b83\u3002\u5979\u7075\u673a\u4e00\u52a8\uff1a\u8fd9\u662f<strong>\u63d0\u5347\u72b6\u6001<\/strong>\u2014\u2014\u4e00\u79cd\u5f3a\u5927\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u597d\u7684\u6d41\u52a8\u5e76\u51cf\u5c11\u591a\u4f59\u7684\u80fd\u91cf\u3002<\/p>\n<p>\u5979\u60f3\u5230\u4e86\u4ee3\u7801\uff1a<\/p>\n<pre>function parentcomponent() {\n  const [sharedstate, setsharedstate] = usestate(\"\");\n  return (\n    &lt;div&gt;\n      &lt;childa sharedstate={sharedstate} \/&gt;\n      &lt;childb setsharedstate={setsharedstate} \/&gt;\n    &lt;\/div&gt;\n  );\n}\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u963f\u6797\u51e0\u4e4e\u53ef\u4ee5\u60f3\u8c61\u5230\u80fd\u91cf\u5411\u4e0a\u79fb\u52a8\uff0c\u786e\u4fdd<strong>childa<\/strong>\u548c<strong>childb<\/strong>\u90fd\u80fd\u591f\u8fdb\u5165\u751f\u547d\u72b6\u6001\u3002 <\/p>\n<hr>\n<p><strong>\u201c\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u201d<\/strong><\/p>\n<p>\u5f53\u4ed6\u4eec\u6df1\u5165\u68ee\u6797\u65f6\uff0c\u963f\u6797\u6ce8\u610f\u5230\u80fd\u91cf\u7c07\u91cd\u53e0\uff0c\u53cd\u5e94\u5143\u7d20\u7684\u6d41\u52a8\u6709\u65f6\u53d8\u5f97\u6df7\u4e71\uff0c\u4e0d\u540c\u7684\u5206\u652f\u4f3c\u4e4e\u5728\u4e89\u593a\u4e3b\u5bfc\u5730\u4f4d\u3002<\/p>\n<p>stateflow\u4e2d\u5c09\u7684\u8868\u60c5\u53d8\u5f97\u4e25\u8083\u8d77\u6765\u3002 \u201c\u8fd9\uff0c\u201d\u4ed6\u6307\u7740\u7ea0\u7f20\u7684\u7c07\u8bf4\uff0c\u201c\u5f53\u4f60\u65e0\u6cd5\u7ef4\u6301<strong>\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90<\/strong>\u65f6\u5c31\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002\u591a\u4e2a\u56fd\u5bb6\u8bd5\u56fe\u7ba1\u7406\u76f8\u540c\u7684\u80fd\u6e90\u4f1a\u5bfc\u81f4\u51b2\u7a81\uff0c\u800c codex \u65e0\u6cd5\u627f\u53d7\u5176\u6838\u5fc3\u6d41\u7a0b\u4e2d\u7684\u51b2\u7a81\u3002\u201d<\/p>\n<p>\u963f\u6797\u77e5\u9053\u4ed6\u7684\u610f\u601d\u3002\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u72b6\u6001\u5e94\u8be5\u5728\u4e00\u4e2a\u5730\u65b9\u8fdb\u884c\u7ba1\u7406\u2014\u2014\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\uff0c\u4ee5\u907f\u514d\u6df7\u4e71\u5e76\u786e\u4fdd\u4e00\u81f4\u6027\u3002<\/p>\n<p>\u4e3a\u4e86\u8bf4\u660e\u8fd9\u4e00\u70b9\uff0cstateflow \u5c06 arin \u5f15\u5bfc\u81f3\u4e00\u4e2a\u4e2d\u592e\u6838\u5fc3\u2014\u2014\u80fd\u91cf\u901a\u8fc7\u5b83\u8109\u52a8\u5e76\u5e73\u7a33\u5730\u5206\u652f\u3002 \u201c\u6240\u6709\u8fd9\u4e9b\u5206\u652f\u90fd\u6e90\u81ea\u8fd9\u4e00\u6e90\u5934\u3002\u4ed6\u4eec\u4e0d\u4f1a\u590d\u5236\u6216\u521b\u5efa\u51b2\u7a81\u7684\u7248\u672c\u3002\u6bcf\u4e00\u6761\u4fe1\u606f\u90fd\u6765\u81ea\u8fd9\u4e2a\u4e2d\u5fc3\u70b9\uff0c\u51cf\u5c11\u6df7\u4e71\u3002\u201d<\/p>\n<p>\u5979\u8bbe\u60f3\u4e86\u4e00\u4e2a\u66f4\u7b80\u6d01\u7684\u4ea7\u54c1\u6a21\u5757\u7248\u672c\uff1a<\/p>\n<pre>const [shareddata, setshareddata] = usestate(\"primary data\");\n\nfunction componenta() {\n  return &lt;div&gt;data: {shareddata}&lt;\/div&gt;;\n}\n\nfunction componentb() {\n  return &lt;button onclick={() =&gt; setshareddata(\"updated data\")}&gt;update&lt;\/button&gt;;\n}\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5171\u4eab\u72b6\u6001\u786e\u4fdd\u4e24\u4e2a\u7ec4\u4ef6\u59cb\u7ec8\u540c\u6b65\uff0c\u5c31\u50cf\u7ef4\u62a4\u5355\u6d41 stateflow \u4e00\u6837\u3002<\/p>\n<hr>\n<p><strong>\u201c\u907f\u514d\u652f\u67f1\u94bb\u5b54\u201d<\/strong><\/p>\n<p>\u68ee\u6797\u5c0f\u8def\u53d8\u7a84\u4e86\uff0cstateflow\u4e2d\u5c09\u5e26\u7740\u5979\u6765\u5230\u4e86\u4e00\u7247\u5bc6\u96c6\u3001\u626d\u66f2\u7684\u6811\u4e1b\u524d\u3002 \u201c\u8fd9\uff0c\u201d\u4ed6\u6307\u7740\u53cd\u5e94\u5143\u7d20\u80fd\u91cf\u7684\u873f\u8712\u8f68\u8ff9\u8bf4\u9053\uff0c\u201c\u662f\u4e00\u6761\u4f4e\u6548\u8def\u5f84\u7684\u4f8b\u5b50\u2014\u2014\u5728\u5230\u8fbe\u9700\u8981\u7684\u5730\u65b9\u4e4b\u524d\u7ecf\u8fc7\u4e86\u592a\u591a\u7684\u4e2d\u95f4\u70b9\u3002\u6211\u4eec\u79f0\u4e4b\u4e3a<strong>\u87ba\u65cb\u94bb\u63a2<\/strong>\u3002\u201d<\/p>\n<p>\u4ed6\u5c06\u624b\u653e\u5728\u80fd\u91cf\u6d41\u4e0a\uff0c\u5f00\u59cb\u5c06\u80fd\u91cf\u7ed5\u8fc7\u4e0d\u5fc5\u8981\u7684\u5206\u652f\uff0c\u76f4\u63a5\u4f20\u9001\u5230\u76ee\u7684\u5730\u3002 \u201c\u6211\u4eec\u9700\u8981\u8003\u8651\u66f4\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u4ece\u4e00\u4e2a\u8282\u70b9\u4f20\u9012\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\u2014\u2014\u4f7f\u7528 <strong>react context<\/strong> \u521b\u5efa\u4e00\u6761\u76f4\u7ebf\u3002\u201d<\/p>\n<p>arin \u8bb0\u5f97\u4e0e\u9700\u8981\u72b6\u6001\u4e00\u8def\u5411\u4e0b\u4f20\u9012\u7684\u6df1\u5c42\u5d4c\u5957\u7ec4\u4ef6\u4f5c\u6597\u4e89\u3002\u87ba\u65cb\u6868\u94bb\u4e95\u7684\u4f4e\u6548\u7387\u662f\u663e\u800c\u6613\u89c1\u7684\u3002<\/p>\n<p>\u4ee3\u66ff\uff1a<\/p>\n<pre>function grandparent() {\n  const [state, setstate] = usestate(\"some state\");\n  return &lt;parent state={state} setstate={setstate} \/&gt;;\n}\n\nfunction parent({ state, setstate }) {\n  return &lt;child state={state} setstate={setstate} \/&gt;;\n}\n\nfunction child({ state, setstate }) {\n  return &lt;div&gt;{state}&lt;\/div&gt;;\n}\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>arin \u5b66\u4f1a\u4e86\u4f7f\u7528 context\uff0c\u7b80\u5316\u4e86\u80fd\u91cf\u7684\u5171\u4eab\u65b9\u5f0f\uff1a<\/p>\n<pre>const statecontext = createcontext();\n\nfunction grandparent() {\n  const [state, setstate] = usestate(\"some state\");\n  return (\n    &lt;statecontext.provider value={{ state, setstate }}&gt;\n      &lt;parent \/&gt;\n    &lt;\/statecontext.provider&gt;\n  );\n}\n\nfunction child() {\n  const { state } = usecontext(statecontext);\n  return &lt;div&gt;{state}&lt;\/div&gt;;\n}\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u8bbe\u7f6e\u4e00\u6761\u76f4\u63a5\u8def\u5f84\uff0c\u80fd\u91cf\u6d41\u52a8\u987a\u7545\uff0c\u964d\u4f4e\u4e86\u590d\u6742\u6027\u2014\u2014\u5c31\u50cf\u7ed5\u8fc7\u56fd\u5bb6\u68ee\u6797\u4e2d\u4e0d\u5fc5\u8981\u7684\u5c0f\u5f84\u4e00\u6837\u3002<\/p>\n<hr>\n<p><strong>\u201c\u7ba1\u7406\u672c\u5730\u72b6\u6001\u4e0e\u5168\u5c40\u72b6\u6001\u201d<\/strong><\/p>\n<p>stateflow\u4e2d\u5c09\u548carin\u7ec8\u4e8e\u5230\u8fbe\u4e86\u4e00\u7247\u7a7a\u5730\uff0c\u591a\u80a1\u80fd\u91cf\u6d41\u6c47\u805a\u4e8e\u6b64\u3002\u4ed6\u8f6c\u5411\u5979\uff0c\u773c\u795e\u4e25\u8083\u3002 \u201c\u6700\u540e\u4e00\u4ef6\u4e8b\uff0c\u5b66\u5458\u3002\u59cb\u7ec8\u4e86\u89e3\u4f55\u65f6\u5728\u672c\u5730\u7ba1\u7406\u80fd\u6e90\u4ee5\u53ca\u4f55\u65f6\u96c6\u4e2d\u7ba1\u7406\u80fd\u6e90\u3002\u201d<\/p>\n<p>\u4ed6\u6307\u7740\u5b64\u7acb\u7ec6\u80de\u5185\u5305\u542b\u7684\u8f83\u5c0f\u7684\u53cd\u5e94\u5143\u7d20\u7c07\u3002 \u201c\u672c\u5730\u72b6\u6001\u6700\u597d\u5728\u5c01\u95ed\u7684\u73af\u5883\u4e2d\u8fdb\u884c\u7ba1\u7406\u2014\u2014\u5c31\u50cf\u8fd9\u91cc\uff0c\u5b83\u53ea\u5f71\u54cd\u8fd9\u4e00\u90e8\u5206\u3002\u4f46\u5f53\u6d89\u53ca\u5230\u9700\u8981\u4e0e\u591a\u4e2a\u96c6\u7fa4\u8fde\u63a5\u7684\u80fd\u6e90\u65f6\uff0c\u5c31\u5fc5\u987b\u63d0\u5347\u5230\u5168\u7403\u6c34\u5e73\u3002\u201d<\/p>\n<p>arin \u70b9\u70b9\u5934\uff0c\u56de\u5fc6\u8d77\u4e86\u4e4b\u524d\u8fc7\u5ea6\u96c6\u4e2d\u5316\u72b6\u6001\u7684\u95ee\u9898\u2014\u2014\u5f53\u67d0\u4e9b\u6d41\u91cf\u53ea\u5f71\u54cd\u4e00\u5c0f\u90e8\u5206\u65f6\uff0c\u7ed9\u6838\u5fc3\u5e26\u6765\u4e86\u592a\u591a\u8d1f\u62c5\u3002\u8fd9\u5c31\u50cf\u8bd5\u56fe\u4e3a\u4e86\u4e00\u7247\u95ea\u70c1\u7684\u53f6\u5b50\u800c\u7a33\u5b9a\u6574\u4e2a\u68ee\u6797\u3002<\/p>\n<p>\u5979\u60f3\u5230\u4e86\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li> <strong>\u672c\u5730\u72b6\u6001<\/strong>\uff1a\u7528\u4e8e\u7ba1\u7406\u4e34\u65f6\u7684\u3001\u72ec\u7acb\u7684\u503c\uff0c\u4f8b\u5982\u5355\u4e2a\u7ec4\u4ef6\u5185\u7684\u8868\u5355\u8f93\u5165\u6216\u5207\u6362\u3002 <\/li>\n<\/ul>\n<pre>  function localcomponent() {\n    const [toggle, settoggle] = usestate(false);\n    return &lt;button onclick={() =&gt; settoggle(!toggle)}&gt;toggle: {toggle.tostring()}&lt;\/button&gt;;\n  }\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n<li> <strong>\u5168\u5c40\u72b6\u6001<\/strong>\uff1a\u5bf9\u4e8e\u5f71\u54cd codex \u591a\u4e2a\u90e8\u5206\u7684\u72b6\u6001\u2014\u2014\u5171\u4eab\u7684\u4e1c\u897f\uff0c\u6bd4\u5982\u7528\u6237\u8bbe\u7f6e\u3002 <\/li>\n<\/ul>\n<pre>  \/\/ Managed via Context or a state library like Redux for broader impact.\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>arin \u770b\u7740 stateflow \u4e2d\u5c09\u719f\u7ec3\u5730\u7ba1\u7406\u6d41\u91cf\uff0c\u51b3\u5b9a\u54ea\u4e9b\u96c6\u4e2d\uff0c\u54ea\u4e9b\u4fdd\u7559\u672c\u5730\u3002\u5979\u73b0\u5728\u660e\u767d\u8fd9\u662f\u4e3a\u4e86\u4fdd\u6301\u5e73\u8861\u2014\u2014\u5e76\u4e0d\u662f\u6bcf\u4e2a\u95ee\u9898\u90fd\u9700\u8981\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<hr>\n<p><strong>\u201c\u5bf9\u56fd\u5bb6\u638c\u63a7\u7684\u53cd\u601d\u201d<\/strong><\/p>\n<p>\u968f\u7740\u8fd9\u4e00\u5929\u7684\u7ed3\u675f\uff0c\u963f\u7433\u7ad9\u5728\u56fd\u5bb6\u68ee\u6797\u7684\u4e2d\u5fc3\uff0c\u88ab\u53d1\u5149\u7684\u80fd\u91cf\u5305\u56f4\uff0c\u5979\u7684\u7406\u89e3\u52a0\u6df1\u4e86\u3002 stateflow\u4e2d\u5c09\u5411\u5979\u70b9\u70b9\u5934\uff0c\u4ed6\u539f\u672c\u575a\u5fcd\u7684\u4e3e\u6b62\u4e2d\u6d41\u9732\u51fa\u4e00\u4e1d\u8ba4\u53ef\u3002<\/p>\n<p>\u201c\u4eca\u5929\u5e72\u5f97\u597d\uff0c\u5b66\u5458\u3002\u8bf7\u8bb0\u4f4f\uff0c\u4fdd\u6301\u5e73\u8861\u548c\u7a33\u5b9a\u662f\u5173\u952e\u3002\u4e0d\u6b63\u786e\u7684\u72b6\u6001\u7ba1\u7406\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0d\u7a33\u5b9a\uff0c\u5c31\u50cf\u6628\u5929\u7684\u751f\u547d\u5468\u671f\u6df7\u4e71\u4e00\u6837\u3002\u6bcf\u80a1\u80fd\u91cf\u6d41\u90fd\u6709\u5b83\u7684\u4f4d\u7f6e\u2014\u2014\u5b66\u4f1a\u6b63\u786e\u653e\u7f6e\u5b83\u3002\u201d<\/p>\n<p>\u963f\u6797\u7b11\u4e86\u3002\u5979\u5b66\u4f1a\u4e86\u5728\u9700\u8981\u65f6\u89e3\u9664\u72b6\u6001\uff0c\u907f\u514d\u6d41\u7a0b\u8fc7\u4e8e\u590d\u6742\uff0c\u7ba1\u7406\u672c\u5730\u4e0e\u5168\u5c40\uff0c\u4ee5\u53ca\u4f7f\u7528\u4e0a\u4e0b\u6587\u6765\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u94bb\u63a2\u3002\u8fd9\u53ea\u662f\u5f00\u59cb\uff0c\u4f46\u5979\u89c9\u5f97\u81ea\u5df1\u66f4\u6709\u80fd\u529b\u5e94\u5bf9\u672a\u6765\u7684\u6311\u6218\u3002<\/p>\n<p>\u6cd5\u5178\u661f\u7403\u7684\u7a33\u5b9a\u6027\u53d6\u51b3\u4e8e\u6bcf\u6761\u80fd\u91cf\u6d41\u7684\u6b63\u786e\u6d41\u52a8\uff0c\u800c\u963f\u6797\u73b0\u5728\u638c\u63e1\u4e86\u5f00\u59cb\u505a\u51fa\u6539\u53d8\u7684\u5de5\u5177\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797\u7684\u60c5\u8282\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e8c\u96c6\uff1a\u5f3a\u5316\u56fd\u5bb6\u68ee\u6797 \u963f\u6797\u5728\u6cd5\u5178\u80fd\u91cf\u5728\u5468\u56f4\u6d41\u52a8\u7684\u7a33\u5b9a\u55e1\u55e1\u58f0\u4e2d\u9192\u6765\uff0c\u53cd\u5e94\u5143\u7d20\u7684\u751f\u52a8\u5149\u8292\u7167\u4eae\u4e86\u56fd\u5bb6\u68ee\u6797\u3002\u4eca\u5929\u662f\u5979\u52a0\u5165\u884c\u661f\u9632\u5fa1\u519b\u56e2\uff08pdc\uff09\u4ee5\u6765\u7684\u7b2c\u4e00\u4e2a\u91cd\u5927\u4efb\u52a1 &#8211; \u5979\u5f88\u7d27\u5f20\u3002\u5979\u88ab\u6307\u6d3e\u4e0e\u56fd\u5bb6\u5b88\u62a4\u8005\u4e00\u8d77\u8bad\u7ec3\uff0c\u4ed6\u4eec\u662fcodex\u6570\u636e\u7ba1\u7406\u7cfb\u7edf\u7684\u4fdd\u62a4\u8005\uff0c\u8d1f\u8d23\u4fdd\u6301\u80fd\u91cf\u6d41\u52a8\u987a\u7545\u5e76\u786e\u4fdd\u7528\u6237\u7684\u7a33\u5b9a\u6027\u3002 \u201c\u5b66\u5458\u963f\u6797\uff0c\u51c6\u5907\u597d\u7b2c\u4e00\u6b21\u771f\u6b63\u7684\u91ce\u5916\u6f14\u4e60\u4e86\u5417\uff1f\u201d\u558a\u51fa\u4e86\u5979\u5f53\u5929\u7684\u8bad\u7ec3\u5e08stateflow\u4e2d\u5c09\u3002\u4e2d\u5c09\u662f\u5b88\u62a4\u8005\u4e2d\u7684\u4e00\u4f4d\u4ee4\u4eba\u656c\u754f\u7684\u4eba\u7269\uff0c\u4ee5\u5176\u7cbe\u5fc3\u7ec4\u7ec7\u56fd\u5bb6\u68ee\u6797\u7684\u65b9\u5f0f\u800c\u95fb\u540d\uff0c\u56fd\u5bb6\u68ee\u6797\u662f\u6cd5\u5178\u7684\u6838\u5fc3\uff0c\u6570\u636e\u5728\u8fd9\u91cc\u6536\u96c6\u3001\u7ef4\u62a4\u548c\u53d1\u9001\u3002 \u963f\u7433\u70b9\u70b9\u5934\uff0c\u611f\u53d7\u5230\u5979\u7684\u4efb\u52a1\u7684\u5206\u91cf\u3002\u5979\u4e0d\u518d\u53ea\u662f\u7ec3\u4e60\u2014\u2014\u6bcf\u4e00\u4e2a\u52a8\u4f5c\u90fd\u5f88\u91cd\u8981\u3002 \u201c\u72b6\u6001\u89e3\u5256\u201d stateflow\u4e2d\u5c09\u5e26\u9886arin\u7a7f\u8fc7\u8302\u5bc6\u7684\u68ee\u6797\uff0c\u4ed6\u7684\u5b58\u5728\u5728\u5145\u6ee1\u6d3b\u529b\u3001\u8109\u52a8\u7684\u53cd\u5e94\u5143\u7d20\u67f1\u82e5\u9690\u82e5\u73b0\u7684\u4e2d\u95f4\u5e73\u9759\u4e0b\u6765\u3002 \u201c\u56fd\u5bb6\u68ee\u6797\u662f\u6cd5\u5178\u5f97\u4ee5\u751f\u5b58\u7684\u52a8\u529b\uff0c\u201d\u4ed6\u6307\u7740\u5468\u56f4\u4e0d\u540c\u65b9\u5411\u6d41\u52a8\u7684\u8bb8\u591a\u80fd\u91cf\u8109\u7edc\u8bf4\u9053\u3002 \u201c\u4fdd\u6301\u5e73\u8861\u7684\u5173\u952e\u662f\u4e86\u89e3\u4f55\u65f6\u521b\u5efa\u3001\u63d0\u5347\u548c\u5171\u4eab\u72b6\u6001\u3002\u5982\u679c\u51fa\u9519\uff0c\u6574\u4e2a\u6d41\u7a0b\u53ef\u80fd\u4f1a\u4e0d\u7a33\u5b9a\u3002\u201d arin \u8bb0\u5f97\u6628\u5929\u5c0f\u51b2\u7a81\u7684\u6df7\u4e71\u2014\u2014\u90a3\u4e9b\u65e0\u5e8f\u7684 bug \u4e0d\u53ef\u9884\u6d4b\u5730\u4f20\u64ad\uff0c\u5c31\u50cf\u65e9\u671f\u751f\u547d\u5468\u671f\u4e8b\u6545\u4e2d\u7684\u4ea7\u54c1\u6a21\u5757\u3002\u56fd\u5bb6\u662f\u6cd5\u5178\u529b\u91cf\u7684\u6838\u5fc3\uff0c\u6ee5\u7528\u5b83\u5c06\u610f\u5473\u7740\u50cf\u5979\u4eb2\u773c\u76ee\u7779\u7684\u90a3\u6837\u7684\u6df7\u4e71\u3002 \u201c\u72b6\u6001\u63d0\u5347\u201d stateflow\u4e2d\u5c09\u505c\u5728\u4e00\u4e2a\u53d1\u5149\u7684\u661f\u56e2\u524d\uff0creactium\u80fd\u91cf\u4ee5\u96c6\u4e2d\u7684\u65b9\u5f0f\u6d41\u52a8\u3002 \u201c\u8fd9\u91cc\u7684\u8fd9\u4e2a\u96c6\u7fa4\uff0c\u201d\u4ed6\u6307\u7740\u8bf4\u9053\uff0c\u201c\u4ee3\u8868\u5171\u4eab\u72b6\u6001\u3002\u9762\u4e34\u7684\u6311\u6218\u662f\u51b3\u5b9a\u5982\u4f55\u7ba1\u7406\u548c\u63d0\u5347\u8fd9\u79cd\u80fd\u91cf\uff0c\u786e\u4fdd\u5b83\u6709\u5229\u4e8e\u6240\u6709\u5468\u56f4\u7684\u7ec4\u4ef6\uff0c\u800c\u4e0d\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u538b\u529b\u3002\u201d \u4ed6\u7ee7\u7eed\u8bf4\u9053\uff0c\u201c\u8bb8\u591a\u5b66\u5458\u72af\u4e86\u5c06\u72b6\u6001\u4fdd\u6301\u5f97\u592a\u6df1\u7684\u9519\u8bef &#8211; \u57cb\u85cf\u5728\u53ef\u80fd\u9700\u8981\u5171\u4eab\u5b83\u7684\u7ec4\u4ef6\u4e2d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u63d0\u5347\u72b6\u6001\uff0c\u4f7f\u5176\u8fbe\u5230\u53ef\u4ee5\u6d41\u5411\u6bcf\u4e2a\u9700\u8981\u5b83\u7684\u90e8\u5206\u7684\u6c34\u5e73\u3002\u201d arin \u770b\u7740 stateflow \u5de7\u5999\u5730\u64cd\u7eb5 reactium \u6d41\uff0c\u5c06\u5176\u5411\u4e0a\u5f15\u5bfc\uff0c\u5141\u8bb8\u591a\u4e2a\u5206\u652f\u540c\u65f6\u8bbf\u95ee\u5b83\u3002\u5979\u7075\u673a\u4e00\u52a8\uff1a\u8fd9\u662f\u63d0\u5347\u72b6\u6001\u2014\u2014\u4e00\u79cd\u5f3a\u5927\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u5b9e\u73b0\u66f4\u597d\u7684\u6d41\u52a8\u5e76\u51cf\u5c11\u591a\u4f59\u7684\u80fd\u91cf\u3002 \u5979\u60f3\u5230\u4e86\u4ee3\u7801\uff1a function parentcomponent() { const [sharedstate, setsharedstate] = usestate(&#8220;&#8221;); return ( &lt;div&gt; &lt;childa sharedstate={sharedstate} \/&gt; &lt;childb setsharedstate={setsharedstate} \/&gt; &lt;\/div&gt; ); } \u767b\u5f55\u540e\u590d\u5236 \u963f\u6797\u51e0\u4e4e\u53ef\u4ee5\u60f3\u8c61\u5230\u80fd\u91cf\u5411\u4e0a\u79fb\u52a8\uff0c\u786e\u4fddchilda\u548cchildb\u90fd\u80fd\u591f\u8fdb\u5165\u751f\u547d\u72b6\u6001\u3002 \u201c\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u201d \u5f53\u4ed6\u4eec\u6df1\u5165\u68ee\u6797\u65f6\uff0c\u963f\u6797\u6ce8\u610f\u5230\u80fd\u91cf\u7c07\u91cd\u53e0\uff0c\u53cd\u5e94\u5143\u7d20\u7684\u6d41\u52a8\u6709\u65f6\u53d8\u5f97\u6df7\u4e71\uff0c\u4e0d\u540c\u7684\u5206\u652f\u4f3c\u4e4e\u5728\u4e89\u593a\u4e3b\u5bfc\u5730\u4f4d\u3002 stateflow\u4e2d\u5c09\u7684\u8868\u60c5\u53d8\u5f97\u4e25\u8083\u8d77\u6765\u3002 \u201c\u8fd9\uff0c\u201d\u4ed6\u6307\u7740\u7ea0\u7f20\u7684\u7c07\u8bf4\uff0c\u201c\u5f53\u4f60\u65e0\u6cd5\u7ef4\u6301\u5355\u4e00\u4e8b\u5b9e\u6765\u6e90\u65f6\u5c31\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002\u591a\u4e2a\u56fd\u5bb6\u8bd5\u56fe\u7ba1\u7406\u76f8\u540c\u7684\u80fd\u6e90\u4f1a\u5bfc\u81f4\u51b2\u7a81\uff0c\u800c codex \u65e0\u6cd5\u627f\u53d7\u5176\u6838\u5fc3\u6d41\u7a0b\u4e2d\u7684\u51b2\u7a81\u3002\u201d [&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-4106","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4106","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=4106"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4106\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}