{"id":1047,"date":"2021-03-09T00:07:57","date_gmt":"2021-03-08T16:07:57","guid":{"rendered":"https:\/\/sora.sound.moe\/?p=1047"},"modified":"2021-03-09T00:07:57","modified_gmt":"2021-03-08T16:07:57","slug":"vue-composition-api-vs-react-hooks","status":"publish","type":"post","link":"https:\/\/sora.sound.moe\/?p=1047","title":{"rendered":"Vue Composition API vs React Hooks"},"content":{"rendered":"\n<p>\u968f\u4fbf\u8bb0\u4e00\u4e0b\u2026\u2026\u51e0\u70b9\u601d\u8003<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2>\u89e3\u51b3\u7684\u95ee\u9898<\/h2>\n\n\n\n<ol><li>\u7ec4\u4ef6\u7ec4\u5408\u80fd\u529b\u4e0d\u8db3\uff0c\u903b\u8f91\u590d\u7528\u80fd\u529b\u4f4e\uff0c\u539f\u6709\u7684<code>mixin<\/code>\u65b9\u6848\u8fc7\u4e8e\u810f\uff0c\u5f88\u96be\u5728\u5927\u578b\u5e94\u7528\u4e2d\u5927\u89c4\u6a21\u4f7f\u7528\u3002<\/li><li>\u968f\u4e4b\u89e3\u51b3\u4e86\u53cd\u590d\u7eb5\u8df3\u95ee\u9898\uff0c\u7531\u4e8e\u4e4b\u524d\u5355\u6587\u4ef6\u7ec4\u4ef6\u7684\u7ed3\u6784\u662fHTML\u6837\u5f0f\u548cJavaScript\u5404\u5360\u4e00\u5757\uff0c\u5bfc\u81f4\u7ec4\u4ef6\u6bd4\u8f83\u5927\u7684\u65f6\u5019\u7ecf\u5e38\u8981\u4e0a\u4e0b\u53cd\u590d\u8df3\u3002Composition API \u53ef\u4ee5\u505a\u5230\u628a\u4e00\u5757\u903b\u8f91\u72ec\u7acb\u5230\u53e6\u5916\u6587\u4ef6\uff0c\u7b80\u5316\u4e86\u6587\u4ef6\u7ed3\u6784\u3002<\/li><\/ol>\n\n\n\n<h2>\u4e0e React Hooks \u7684\u533a\u522b<\/h2>\n\n\n\n<ol><li>React Hooks \u6bcf\u6b21\u91cd\u6e32\u67d3\u5373\u6267\u884c\u4e00\u6b21\uff0cVue Setup \u51fd\u6570\u53ea\u5728\u7ec4\u4ef6\u521d\u59cb\u5316\u6267\u884c\u4e00\u6b21\u3002<\/li><li>immutable \/ mutable \u7406\u5ff5\u5dee\u522b\u3002React Hooks \u521b\u5efa\u4e00\u4e2a State \u65f6\u540c\u65f6\u7ed9\u51fa\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u66f4\u65b0\u503c\u3002Vue \u5219\u81ea\u52a8\u5305\u88c5\u4e3a Proxy \u81ea\u52a8\u76d1\u542c\u53d8\u5316\uff0c\u505a\u5230\u53cc\u5411\u7ed1\u5b9a\u3002<\/li><\/ol>\n\n\n\n<h2>\u601d\u8003<\/h2>\n\n\n\n<ol><li>React Hooks \u7ee7\u627f\u4e86 React \u7cbe\u795e\uff0c\u6bcf\u6b21\u6e32\u67d3\u90fd\u4f1a\u6267\u884c\u4e00\u6b21\uff0c\u8fd9\u5fc5\u7136\u4f1a\u5e26\u6765\u989d\u5916\u7684\u5f00\u9500\u3002\u5373\u4f7f<code>useMemo<\/code>\/<code>useCallback<\/code>\u4e4b\u7c7b\u7684\u51fd\u6570\u90fd\u63d0\u4f9b\u7b2c\u4e8c\u53c2\u6570\u7528\u4e8e\u63a7\u5236\u662f\u5426\u91cd\u65b0\u6267\u884c\uff0c\u4f46\u8fd9\u4e00\u6bd4\u8f83\u4e5f\u662f\u9700\u8981\u5f00\u9500\u7684\uff0c\u5f53\u4f9d\u8d56\u53c2\u6570\u6bd4\u8f83\u591a\u7684\u65f6\u5019\u9700\u8981\u5bf9\u6bd4\u7684\u4e5f\u4f1a\u591a\u3002\u5c3d\u7ba1<code>Object.is<\/code>\u5bf9\u6bd4\u53c2\u6570\u662f\u5426\u76f8\u7b49\u5f00\u9500\u5f88\u5c0f\uff0c\u4f46\u8fd9\u4e5f\u662f\u4e00\u7b14\u5f00\u9500\u3002Vue \u7684\u4f9d\u8d56\u6536\u96c6\u53cd\u800c\u53ea\u662f\u5728\u9700\u8981\u66f4\u65b0\u7684\u65f6\u5019\u624d\u66f4\u65b0\uff0c\u5728\u6027\u80fd\u4e0a\u4f3c\u4e4e\u66f4\u6709\u4f18\u52bf\u3002<\/li><li>Vue \u7684\u81ea\u52a8\u5305\u88c5\uff0c\u7ee7\u627f\u4e86 Vue \u4e00\u8d2f\u7684\u8bed\u6cd5\u7cd6\u7cbe\u795e\uff0c\u5c06\u4e00\u4e9b\u56fa\u5b9a\u7684\u4e8b\u60c5\u4ea4\u7ed9\u6846\u67b6\u6765\u5b8c\u6210\u3002\u4e0d\u8fc7\uff0c\u5728 Template \u4e2d\u4e0d\u9700\u8981\u5199.current\uff0cScript \u4e2d\u8981\u5199\u8fd9\u4e00\u5dee\u522b\u7740\u5b9e\u6709\u4e9b\u4e11\u964b\uff0c\u540e\u7eed\u63d0\u51fa\u7684 Refs \u63d0\u6848\u4e5f\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u800c\u8fd9\u4e00\u63d0\u6848\u7684\u6548\u679c\u662f\u597d\u7684\uff0c\u5374\u53c8\u5f15\u5165\u4e86\u65b0\u7684\u6982\u5ff5\u3002\u8fd9\u662f\u4e00\u4e2a\u89c1\u4ec1\u89c1\u667a\u7684\u64cd\u4f5c\uff0c\u6211\u4e2a\u4eba\u89c9\u5f97\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\u3002<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u4fbf\u8bb0\u4e00\u4e0b\u2026\u2026\u51e0\u70b9\u601d\u8003<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"twentyseventeen-featured-image":false,"twentyseventeen-thumbnail-avatar":false},"uagb_author_info":{"display_name":"Sora","author_link":"https:\/\/sora.sound.moe\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":"\u968f\u4fbf\u8bb0\u4e00\u4e0b\u2026\u2026\u51e0\u70b9\u601d\u8003","_links":{"self":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/1047"}],"collection":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1047"}],"version-history":[{"count":0,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/1047\/revisions"}],"wp:attachment":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}