{"id":16312,"date":"2026-03-16T13:41:42","date_gmt":"2026-03-16T05:41:42","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312"},"modified":"2026-03-16T17:35:14","modified_gmt":"2026-03-16T09:35:14","slug":"%e5%9b%9b%e3%80%81%e5%89%af%e4%bd%9c%e7%94%a8","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312","title":{"rendered":"\u56db\u3001\u526f\u4f5c\u7528"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E4%B8%80%E3%80%81%E5%89%AF%E4%BD%9C%E7%94%A8%E7%9A%84%E6%A6%82%E5%BF%B5\" title=\"\u4e00\u3001\u526f\u4f5c\u7528\u7684\u6982\u5ff5\">\u4e00\u3001\u526f\u4f5c\u7528\u7684\u6982\u5ff5<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E4%BA%8C%E3%80%81%E7%9B%B8%E5%85%B3API\" title=\"\u4e8c\u3001\u76f8\u5173API\">\u4e8c\u3001\u76f8\u5173API<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#1LaunchedEffect\" title=\"1.LaunchedEffect\">1.LaunchedEffect<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%93%8C_1%EF%BC%89LaunchedEffect%E6%98%AF%E4%BB%80%E4%B9%88\" title=\"\ud83d\udccc 1\uff09LaunchedEffect\u662f\u4ec0\u4e48\">\ud83d\udccc 1\uff09LaunchedEffect\u662f\u4ec0\u4e48<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%8E%AF_2%EF%BC%89LaunchedEffect%E7%9A%84%E4%B8%89%E7%A7%8D%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F\" title=\"\ud83c\udfaf 2\uff09LaunchedEffect\u7684\u4e09\u79cd\u5de5\u4f5c\u6a21\u5f0f\">\ud83c\udfaf 2\uff09LaunchedEffect\u7684\u4e09\u79cd\u5de5\u4f5c\u6a21\u5f0f<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E6%A8%A1%E5%BC%8F1%EF%BC%9A%E8%B7%9F%E9%9A%8F%E5%B1%8F%E5%B9%95%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%EF%BC%88%E6%B0%B8%E4%B8%8D%E9%87%8D%E5%90%AF%EF%BC%89\" title=\"\u6a21\u5f0f1\uff1a\u8ddf\u968f\u5c4f\u5e55\u751f\u547d\u5468\u671f\uff08\u6c38\u4e0d\u91cd\u542f\uff09\">\u6a21\u5f0f1\uff1a\u8ddf\u968f\u5c4f\u5e55\u751f\u547d\u5468\u671f\uff08\u6c38\u4e0d\u91cd\u542f\uff09<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E6%A8%A1%E5%BC%8F2%EF%BC%9A%E5%93%8D%E5%BA%94%E5%8F%98%E5%8C%96%E9%87%8D%E5%90%AF\" title=\"\u6a21\u5f0f2\uff1a\u54cd\u5e94\u53d8\u5316\u91cd\u542f\">\u6a21\u5f0f2\uff1a\u54cd\u5e94\u53d8\u5316\u91cd\u542f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E6%A8%A1%E5%BC%8F3%EF%BC%9A%E6%9D%A1%E4%BB%B6%E6%89%A7%E8%A1%8C%EF%BC%88%E9%85%8D%E5%90%88if%EF%BC%89\" title=\"\u6a21\u5f0f3\uff1a\u6761\u4ef6\u6267\u884c\uff08\u914d\u5408if\uff09\">\u6a21\u5f0f3\uff1a\u6761\u4ef6\u6267\u884c\uff08\u914d\u5408if\uff09<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%92%A1_3%EF%BC%89%E6%9C%80%E6%98%93%E9%94%99%E7%9A%84%E9%99%B7%E9%98%B1%EF%BC%88%E5%BF%85%E7%9C%8B%EF%BC%81%EF%BC%89\" title=\"\ud83d\udca1 3\uff09\u6700\u6613\u9519\u7684\u9677\u9631\uff08\u5fc5\u770b\uff01\uff09\">\ud83d\udca1 3\uff09\u6700\u6613\u9519\u7684\u9677\u9631\uff08\u5fc5\u770b\uff01\uff09<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%E9%99%B7%E9%98%B11%EF%BC%9A%E5%9C%A8LaunchedEffect%E9%87%8C%E8%AF%BB%E7%8A%B6%E6%80%81\" title=\"\u9677\u96311\uff1a\u5728LaunchedEffect\u91cc\u8bfb\u72b6\u6001\">\u9677\u96311\uff1a\u5728LaunchedEffect\u91cc\u8bfb\u72b6\u6001<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#2rememberCoroutineScope\" title=\"2.rememberCoroutineScope\">2.rememberCoroutineScope<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#3rememberUpdatedState\" title=\"3.rememberUpdatedState\">3.rememberUpdatedState<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#4DisposableEffect\" title=\"4.DisposableEffect\">4.DisposableEffect<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%93%8C_1%EF%BC%89DisposableEffect%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" title=\"\ud83d\udccc 1\uff09DisposableEffect\u662f\u4ec0\u4e48\uff1f\">\ud83d\udccc 1\uff09DisposableEffect\u662f\u4ec0\u4e48\uff1f<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#5SideEffect\" title=\"5.SideEffect\">5.SideEffect<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%8E%AF_1%EF%BC%89SideEffect%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" title=\"\ud83c\udfaf 1\uff09SideEffect\u662f\u4ec0\u4e48\uff1f\">\ud83c\udfaf 1\uff09SideEffect\u662f\u4ec0\u4e48\uff1f<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-17\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#6produceState\" title=\"6.produceState\">6.produceState<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-18\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%8E%AF1%EF%BC%89_produceState%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" title=\"\ud83c\udfaf1\uff09 produceState\u662f\u4ec0\u4e48\uff1f\">\ud83c\udfaf1\uff09 produceState\u662f\u4ec0\u4e48\uff1f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-19\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#2%E4%B8%8Eremember%EF%BC%88%E5%B8%A6key%EF%BC%89%E5%AF%B9%E6%AF%94\" title=\"2.\u4e0eremember\uff08\u5e26key\uff09\u5bf9\u6bd4\">2.\u4e0eremember\uff08\u5e26key\uff09\u5bf9\u6bd4<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-20\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#7derivedStateOf_%EF%BC%88%E6%B4%BE%E7%94%9F%E7%8A%B6%E6%80%81%EF%BC%89\" title=\"7.derivedStateOf \uff08\u6d3e\u751f\u72b6\u6001\uff09\">7.derivedStateOf \uff08\u6d3e\u751f\u72b6\u6001\uff09<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-21\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#8snapshotFlow\" title=\"8.snapshotFlow\">8.snapshotFlow<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-22\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16312\/#%F0%9F%8E%AF_1%EF%BC%89snapshotFlow%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\" title=\"\ud83c\udfaf 1\uff09snapshotFlow\u662f\u4ec0\u4e48\uff1f\">\ud83c\udfaf 1\uff09snapshotFlow\u662f\u4ec0\u4e48\uff1f<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E4%B8%80%E3%80%81%E5%89%AF%E4%BD%9C%E7%94%A8%E7%9A%84%E6%A6%82%E5%BF%B5\"><\/span>\u4e00\u3001\u526f\u4f5c\u7528\u7684\u6982\u5ff5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><strong>\u526f\u4f5c\u7528<\/strong>\u662f\u6307\u53d1\u751f\u5728\u53ef\u7ec4\u5408\u51fd\u6570\u4f5c\u7528\u57df\u4e4b\u5916\u7684\u5e94\u7528\u72b6\u6001\u53d8\u5316\u3002\u7531\u4e8e\u53ef\u7ec4\u5408\u9879\u53ef\u80fd\u56e0\u91cd\u7ec4\u800c\u88ab\u9891\u7e41\u3001\u65e0\u5e8f\u5730\u6267\u884c\uff0c\u7406\u60f3\u60c5\u51b5\u4e0b\u5e94\u4fdd\u6301\u65e0\u526f\u4f5c\u7528\u3002\u4f46\u5f53\u9700\u8981\u6267\u884c\u5982\u663e\u793a\u5f39\u7a97\u3001\u53d1\u8d77\u7f51\u7edc\u8bf7\u6c42\u7b49\u64cd\u4f5c\u65f6\uff0c\u5fc5\u987b\u4f7f\u7528\u4e13\u95e8\u7684 Effect API \u5728\u53d7\u63a7\u73af\u5883\u4e2d\u8fdb\u884c\uff0c\u4ee5\u786e\u4fdd\u884c\u4e3a\u53ef\u9884\u6d4b\u4e14\u4e0e\u53ef\u7ec4\u5408\u9879\u7684\u751f\u547d\u5468\u671f\u4e00\u81f4\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E4%BA%8C%E3%80%81%E7%9B%B8%E5%85%B3API\"><\/span>\u4e8c\u3001\u76f8\u5173API<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"1LaunchedEffect\"><\/span>1.LaunchedEffect<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%93%8C_1%EF%BC%89LaunchedEffect%E6%98%AF%E4%BB%80%E4%B9%88\"><\/span>\ud83d\udccc 1\uff09LaunchedEffect\u662f\u4ec0\u4e48<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>\u5b98\u65b9\u5b9a\u4e49<\/strong>\uff1a\u4e00\u4e2a\u53ef\u7ec4\u5408\u51fd\u6570\uff0c\u7528\u4e8e\u5728<strong>\u53ef\u7ec4\u5408\u9879\u7684\u751f\u547d\u5468\u671f\u5185<\/strong>\u6267\u884c<strong>\u6302\u8d77\u51fd\u6570<\/strong>\u3002<\/p>\n<p><strong>\u901a\u4fd7\u7406\u89e3<\/strong>\uff1a\u5b83\u662f\u4e00\u4e2a\u201c<strong>\u81ea\u5e26\u751f\u547d\u5468\u671f\u7684\u534f\u7a0b\u542f\u52a8\u5668<\/strong>\u201d\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%8E%AF_2%EF%BC%89LaunchedEffect%E7%9A%84%E4%B8%89%E7%A7%8D%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F\"><\/span>\ud83c\udfaf 2\uff09LaunchedEffect\u7684\u4e09\u79cd\u5de5\u4f5c\u6a21\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"%E6%A8%A1%E5%BC%8F1%EF%BC%9A%E8%B7%9F%E9%9A%8F%E5%B1%8F%E5%B9%95%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%EF%BC%88%E6%B0%B8%E4%B8%8D%E9%87%8D%E5%90%AF%EF%BC%89\"><\/span>\u6a21\u5f0f1\uff1a\u8ddf\u968f\u5c4f\u5e55\u751f\u547d\u5468\u671f\uff08\u6c38\u4e0d\u91cd\u542f\uff09<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>LaunchedEffect(Unit) {  \/\/ Unit\u6c38\u8fdc\u4e0d\u4f1a\u53d8\n    \/\/ \u8fd9\u4e2a\u534f\u7a0b\u548c\u53ef\u7ec4\u5408\u9879\u540c\u751f\u5171\u6b7b\n    while (true) {\n        delay(1000)\n        \/\/ \u6bcf\u79d2\u6267\u884c\u4e00\u6b21\uff0c\u76f4\u5230\u5c4f\u5e55\u9500\u6bc1\n    }\n}<\/code><\/pre>\n<p><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u8f6e\u8be2\u3001\u6301\u7eed\u52a8\u753b\u3001WebSocket\u8fde\u63a5<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E6%A8%A1%E5%BC%8F2%EF%BC%9A%E5%93%8D%E5%BA%94%E5%8F%98%E5%8C%96%E9%87%8D%E5%90%AF\"><\/span>\u6a21\u5f0f2\uff1a\u54cd\u5e94\u53d8\u5316\u91cd\u542f<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>LaunchedEffect(userId) {  \/\/ userId\u53d8\u5316\u65f6\u91cd\u542f\n    \/\/ \u65e7\u7684\u7f51\u7edc\u8bf7\u6c42\u88ab\u53d6\u6d88\n    val userData = api.fetchUser(userId)  \/\/ \u6302\u8d77\u51fd\u6570\n    \/\/ \u7528\u65b0\u6570\u636e\u66f4\u65b0\u754c\u9762\n}<\/code><\/pre>\n<p><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u4f9d\u8d56\u53c2\u6570\u7684\u7f51\u7edc\u8bf7\u6c42\u3001\u641c\u7d22\u9632\u6296<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E6%A8%A1%E5%BC%8F3%EF%BC%9A%E6%9D%A1%E4%BB%B6%E6%89%A7%E8%A1%8C%EF%BC%88%E9%85%8D%E5%90%88if%EF%BC%89\"><\/span>\u6a21\u5f0f3\uff1a\u6761\u4ef6\u6267\u884c\uff08\u914d\u5408if\uff09<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>if (shouldLoad) {\n    LaunchedEffect(Unit) {\n        \/\/ \u53ea\u6709\u5f53shouldLoad\u4e3atrue\u65f6\u624d\u6267\u884c\n        loadData()\n    }\n}\n\/\/ \u5f53shouldLoad\u53d8false\uff0c\u6548\u5e94\u9000\u51fa\u7ec4\u5408\uff0c\u534f\u7a0b\u53d6\u6d88<\/code><\/pre>\n<p><strong>\u9002\u7528\u573a\u666f<\/strong>\uff1a\u6a21\u6001\u6846\u51fa\u73b0\u65f6\u52a0\u8f7d\u6570\u636e\u3001\u6761\u4ef6\u6027\u76d1\u542c<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%92%A1_3%EF%BC%89%E6%9C%80%E6%98%93%E9%94%99%E7%9A%84%E9%99%B7%E9%98%B1%EF%BC%88%E5%BF%85%E7%9C%8B%EF%BC%81%EF%BC%89\"><\/span>\ud83d\udca1 3\uff09\u6700\u6613\u9519\u7684\u9677\u9631\uff08\u5fc5\u770b\uff01\uff09<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"%E9%99%B7%E9%98%B11%EF%BC%9A%E5%9C%A8LaunchedEffect%E9%87%8C%E8%AF%BB%E7%8A%B6%E6%80%81\"><\/span>\u9677\u96311\uff1a\u5728LaunchedEffect\u91cc\u8bfb\u72b6\u6001<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>var counter by remember { mutableStateOf(0) }\n\nLaunchedEffect(Unit) {\n    while (true) {\n        delay(1000)\n        println(&quot;\u8ba1\u6570\uff1a$counter&quot;)  \/\/ \u274c counter\u6c38\u8fdc\u662f0\uff01\n        \/\/ \u56e0\u4e3aLaunchedEffect\u542f\u52a8\u65f6\u6355\u83b7\u4e86counter\u7684\u521d\u59cb\u503c\n    }\n}<\/code><\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong>\uff1a\u7528<code>rememberUpdatedState<\/code><\/p>\n<p>kotlin<\/p>\n<pre><code>val currentCounter by rememberUpdatedState(counter)\n\nLaunchedEffect(Unit) {\n    while (true) {\n        delay(1000)\n        println(&quot;\u8ba1\u6570\uff1a$currentCounter&quot;)  \/\/ \u2705 \u6bcf\u6b21\u90fd\u662f\u6700\u65b0\u7684\n    }\n}<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"2rememberCoroutineScope\"><\/span>2.rememberCoroutineScope<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"3rememberUpdatedState\"><\/span>3.rememberUpdatedState<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"4DisposableEffect\"><\/span>4.DisposableEffect<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%93%8C_1%EF%BC%89DisposableEffect%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>\ud83d\udccc 1\uff09DisposableEffect\u662f\u4ec0\u4e48\uff1f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><strong>\u5b98\u65b9\u5b9a\u4e49<\/strong>\uff1a\u7528\u4e8e\u9700\u8981<strong>\u624b\u52a8\u6e05\u7406<\/strong>\u7684\u526f\u4f5c\u7528\uff0c\u5f53\u952e\u53d8\u5316\u6216\u9000\u51fa\u7ec4\u5408\u65f6\u6267\u884c\u6e05\u7406\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u901a\u4fd7\u7406\u89e3<\/strong>\uff1a\u5b83\u5f3a\u5236\u4f60\u5199<code>onDispose { }<\/code>\uff0c\u786e\u4fdd\u8d44\u6e90\u88ab\u6b63\u786e\u91ca\u653e\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5SideEffect\"><\/span>5.SideEffect<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h4><span class=\"ez-toc-section\" id=\"%F0%9F%8E%AF_1%EF%BC%89SideEffect%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>\ud83c\udfaf 1\uff09<strong>SideEffect\u662f\u4ec0\u4e48\uff1f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><strong>\u5b98\u65b9\u5b9a\u4e49<\/strong>\uff1a\u5728\u6bcf\u6b21<strong>\u6210\u529f\u91cd\u7ec4\u540e<\/strong>\u6267\u884c\u7684\u526f\u4f5c\u7528\uff0c\u7528\u4e8e\u5c06Compose\u72b6\u6001\u540c\u6b65\u5230\u975eCompose\u73af\u5883\u3002<\/p>\n<p><strong>\u4e00\u53e5\u8bdd\u7406\u89e3<\/strong>\uff1a\u5b83\u662fCompose\u7684&quot;<strong>\u72b6\u6001\u540c\u6b65\u5668<\/strong>&quot;\u2014\u2014\u6bcf\u6b21\u754c\u9762\u66f4\u65b0\u5b8c\uff0c\u5c31\u81ea\u52a8\u901a\u77e5\u5916\u90e8\u4e16\u754c\u3002<\/p>\n<p><strong>SideEffect\u5c31\u50cf&quot;\u72b6\u6001\u5e7f\u64ad\u5458&quot;\u2014\u2014\u6bcf\u6b21\u754c\u9762\u66f4\u65b0\u5b8c\uff0c\u5b83\u5c31\u81ea\u52a8\u5bf9\u5916\u558a\u4e00\u55d3\u5b50\uff1a&quot;\u6700\u65b0\u72b6\u6001\u6765\u5566\uff01&quot;<\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"6produceState\"><\/span>6.produceState<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h4><span class=\"ez-toc-section\" id=\"%F0%9F%8E%AF1%EF%BC%89_produceState%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>\ud83c\udfaf1\uff09 <strong>produceState\u662f\u4ec0\u4e48\uff1f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><strong>\u5b98\u65b9\u5b9a\u4e49<\/strong>\uff1a\u4e00\u4e2a\u5c06<strong>\u975eCompose\u72b6\u6001<\/strong>\uff08\u5982<code>Flow<\/code>\u3001<code>LiveData<\/code>\u3001\u56de\u8c03\uff09\u8f6c\u6362\u4e3aCompose\u7684<code>State<\/code>\u7684API\u3002<\/p>\n<p><strong>\u4e00\u53e5\u8bdd\u7406\u89e3<\/strong>\uff1a\u5b83\u662f<strong>\u6570\u636e\u8f6c\u6362\u5668<\/strong>\u2014\u2014\u628a\u5916\u90e8\u4e16\u754c\u7684\u6570\u636e\u6d41\uff0c\u53d8\u6210Compose\u754c\u9762\u80fd\u76f4\u63a5\u7528\u7684State\uff01<\/p>\n<h4><span class=\"ez-toc-section\" id=\"2%E4%B8%8Eremember%EF%BC%88%E5%B8%A6key%EF%BC%89%E5%AF%B9%E6%AF%94\"><\/span>2.\u4e0eremember\uff08\u5e26key\uff09\u5bf9\u6bd4<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u5bf9\u6bd4\u7ef4\u5ea6<\/th>\n<th style=\"text-align: left;\">produceState<\/th>\n<th style=\"text-align: left;\">remember (\u5e26key)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><strong>\u672c\u8d28<\/strong><\/td>\n<td style=\"text-align: left;\"><strong>\u6267\u884c\u64cd\u4f5c<\/strong> + <strong>\u8fd4\u56deState<\/strong><\/td>\n<td style=\"text-align: left;\"><strong>\u7f13\u5b58\u503c<\/strong> + <strong>\u8fd4\u56de\u4efb\u610f\u7c7b\u578b<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u6267\u884c\u65f6\u673a<\/strong><\/td>\n<td style=\"text-align: left;\">\u8fdb\u5165\u7ec4\u5408\u6216key\u53d8\u5316\u65f6<strong>\u542f\u52a8\u534f\u7a0b<\/strong><\/td>\n<td style=\"text-align: left;\">\u8fdb\u5165\u7ec4\u5408\u6216key\u53d8\u5316\u65f6<strong>\u7acb\u5373\u8ba1\u7b97<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u8fd4\u56de\u503c<\/strong><\/td>\n<td style=\"text-align: left;\">\u6c38\u8fdc\u662f<code>State&lt;T&gt;<\/code><\/td>\n<td style=\"text-align: left;\">\u53ef\u4ee5\u662f<strong>\u4efb\u610f\u7c7b\u578b<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u534f\u7a0b\u652f\u6301<\/strong><\/td>\n<td style=\"text-align: left;\">\u2705 \u652f\u6301\u6302\u8d77\u51fd\u6570<\/td>\n<td style=\"text-align: left;\">\u274c \u4e0d\u652f\u6301\u6302\u8d77<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u751f\u547d\u5468\u671f<\/strong><\/td>\n<td style=\"text-align: left;\">\u6709\u72ec\u7acb\u7684\u534f\u7a0b\u751f\u547d\u5468\u671f<\/td>\n<td style=\"text-align: left;\">\u53ea\u662f\u4e00\u4e2a\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u5178\u578b\u7528\u9014<\/strong><\/td>\n<td style=\"text-align: left;\">\u5f02\u6b65\u6570\u636e\u52a0\u8f7d<\/td>\n<td style=\"text-align: left;\">\u7f13\u5b58\u8ba1\u7b97\u7ed3\u679c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"7derivedStateOf_%EF%BC%88%E6%B4%BE%E7%94%9F%E7%8A%B6%E6%80%81%EF%BC%89\"><\/span>7.derivedStateOf \uff08\u6d3e\u751f\u72b6\u6001\uff09<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"8snapshotFlow\"><\/span>8.snapshotFlow<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h4><span class=\"ez-toc-section\" id=\"%F0%9F%8E%AF_1%EF%BC%89snapshotFlow%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F\"><\/span>\ud83c\udfaf 1\uff09<strong>snapshotFlow\u662f\u4ec0\u4e48\uff1f<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><strong>\u5b98\u65b9\u5b9a\u4e49<\/strong>\uff1a\u4e00\u4e2a\u5c06Compose\u7684<code>State<\/code>\u5bf9\u8c61\u8f6c\u6362\u4e3a<strong>\u51b7Flow<\/strong>\u7684\u51fd\u6570\u3002<\/p>\n<p><strong>\u4e00\u53e5\u8bdd\u7406\u89e3<\/strong>\uff1a\u5b83\u662f<strong>\u72b6\u6001\u76d1\u542c\u5668<\/strong>\u2014\u2014\u628aCompose\u4e16\u754c\u7684\u72b6\u6001\u53d8\u5316\uff0c\u8f6c\u6362\u6210Flow\u4e16\u754c\u7684\u6570\u636e\u6d41\uff01<\/p>\n<button class=\"simplefavorite-button\" data-postid=\"16312\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u4e00\u3001\u526f\u4f5c\u7528\u7684\u6982\u5ff5\u4e8c\u3001\u76f8\u5173API1.LaunchedEffect\ud83d\udccc 1\uff09LaunchedEffe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1252],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16312"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16312"}],"version-history":[{"count":19,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16312\/revisions"}],"predecessor-version":[{"id":16334,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16312\/revisions\/16334"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16312"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}