{"id":149200,"date":"2020-08-19T09:37:10","date_gmt":"2020-08-19T01:37:10","guid":{"rendered":"http:\/\/4563.org\/?p=149200"},"modified":"2020-08-19T09:37:10","modified_gmt":"2020-08-19T01:37:10","slug":"ahooks-%e2%80%a2-usetable-%e6%9f%a5%e8%af%a2%e8%a1%a8%e6%a0%bc%e5%9c%ba%e6%99%af%e6%8f%92%e4%bb%b6%e5%8c%96-hook-%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=149200","title":{"rendered":"ahooks \u2022 useTable &#8211; \u67e5\u8be2\u8868\u683c\u573a\u666f\u63d2\u4ef6\u5316 Hook \u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  ahooks \u2022 useTable &#8211; \u67e5\u8be2\u8868\u683c\u573a\u666f\u63d2\u4ef6\u5316 Hook \u89e3\u51b3\u65b9\u6848               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : monkindey <\/span>  <span><i><\/i> 10<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<ul>\n<li>\u5b98\u7f51 https:\/\/usetable-ahooks.js.org\/<\/li>\n<li>Github https:\/\/github.com\/ahooksjs\/useTable\/<\/li>\n<\/ul>\n<h2>\u4e3a\u4ec0\u4e48\u8981\u6709 useTable \uff1f<\/h2>\n<p>\u5728\u4e2d\u540e\u53f0\u573a\u666f\u4e2d\uff0c\u67e5\u8be2\u8868\u683c\u7684\u573a\u666f\u5360\u6bd4\u8f83\u9ad8\u3002\u4f60\u4f1a\u53d1\u73b0\u8be5\u573a\u666f\u5199\u8d77\u4ee3\u7801\u4f1a\u5145\u65a5\u7740\u91cd\u590d\u6027\u7684\u4ee3\u7801\uff0c\u6bd4\u5982\u70b9\u51fb\u4e0b\u4e00\u9875\u7684\u65f6\u5019\uff0c\u4f60\u9700\u8981\u628a\u8868\u5355\u67e5\u8be2\u6761\u4ef6\u5e26\u8fc7\u53bb\uff0c\u70b9\u51fb\u67e5\u8be2\u7684\u65f6\u5019\u4f60\u9700\u8981\u628a\u9875\u7801\u5f52\u4e3a 1 \u7b49\u5e38\u89c4\u903b\u8f91\u3002\u5f53\u7136\u8fd8\u6709\u5f88\u591a\u589e\u5f3a\u529f\u80fd\uff0c\u6bd4\u5982\u6392\u5e8f\u3001filter \u3001\u591a\u9009\u529f\u80fd\u3002<\/p>\n<p>\u6211\u4eec\u9762\u4e34\u201c\u9ad8\u6548\u201d\u548c\u201c\u7075\u6d3b\u201d\u6743\u8861\u95ee\u9898\uff0c\u9ad8\u6548\u7684\u8bdd\u53ef\u4ee5\u4e00\u4e2a\u7ec4\u4ef6\u6765\u5b9e\u73b0\u4e0a\u9762\u529f\u80fd\u7136\u540e\u901a\u8fc7 props \u6765\u914d\u7f6e\uff0c\u8fd9\u6837\u5b50\u53ef\u80fd\u4f1a\u51cf\u5c11\u4e86\u7075\u6d3b\u6027\uff0c\u7075\u6d3b\u53c8\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u65b9\u624b\u5199\u5f88\u591a\u4ee3\u7801\u624d\u80fd\u5b8c\u6210\u4e00\u4e2a\u529f\u80fd\uff0c\u5931\u53bb\u4e86\u9ad8\u6548\u6027\u3002<\/p>\n<p>\u6700\u540e\u501f\u9274\u4e86 Egg \u548c Babel \u7684\u601d\u60f3\uff0c\u901a\u8fc7 Core + Plugin \u7684\u65b9\u5f0f\u6765\u5e73\u8861\u201c\u9ad8\u6548\u201d\u548c\u201c\u7075\u6d3b\u201d\u3002\u540c\u65f6\u8bbe\u8ba1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u51cf\u5c11\u65b0\u6982\u5ff5\u51fa\u73b0\uff0c\u5c3d\u91cf\u4f7f\u7528\u4e1a\u754c\u901a\u7528\u7684\u65b9\u6848\u6765\u51cf\u5c11\u5b66\u4e60\u6210\u672c\u3002\u6211\u4eec\u82b1\u8d39\u5927\u91cf\u65f6\u95f4\u53bb\u601d\u8003\u63d2\u4ef6\u8bbe\u8ba1\uff0c\u5e76\u4e14\u6570\u5b57\u4f9b\u5e94\u94fe\u5df2\u7ecf\u505a\u7b2c\u4e00\u4e2a\u5403\u8783\u87f9\u7684\u4eba\uff0c\u57fa\u672c\u4e0a\u6240\u6709\u7684\u67e5\u8be2\u8868\u683c\u573a\u666f\u90fd\u7528\u8fd9\u4e2a\u65b9\u6848\u4e86\u3002\u73b0\u5728\u662f\u65f6\u95f4\u653e\u51fa\u6765\u8ba9\u5927\u5bb6 Review \u4e0b\u4e86\uff0c\u671f\u671b\u6709\u66f4\u591a\u573a\u666f\u7684\u8f93\u5165\uff0c\u8fd9\u6837\u5b50 useTable \u624d\u80fd\u505a\u5f97\u66f4\u597d\u3002<\/p>\n<\/p>\n<h2>useTable \u662f\u4ec0\u4e48\uff1f<\/h2>\n<p>useTable \u9488\u5bf9\u7684\u662f\u67e5\u8be2\u8868\u683c\u573a\u666f\u7684\u4e00\u4e9b\u72b6\u6001\u903b\u8f91\u5904\u7406\uff0c\u6bd4\u5982\u8bf7\u6c42\u7684\u65f6\u5019\u6709 loading\uff0c\u8bf7\u6c42\u6210\u529f\u4e4b\u540e\u8bbe\u7f6e dataSource\uff0c\u70b9\u51fb\u4e0b\u4e00\u9875\u7684\u65f6\u5019\u8bf7\u6c42\u7b49\u3002\u672c\u8eab\u4e0d\u5173\u5fc3 View \u5c42\uff0c\u5e76\u4e0d\u662f\u91cd\u65b0\u9020\u4e00\u4e2a Table \u7ec4\u4ef6\u3002<\/p>\n<p>\u5b83\u5305\u542b\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n<ul>\n<li>  <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3108515\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : otakustay <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u8ba4\u4e3a\u5728 hook \u4e0a\u8fd9\u4e48\u73a9 plugin \u7684\u65b9\u6848\u975e\u5e38\u626f\u8c08\uff0chook \u672c\u6765\u5c31\u662f\u4e00\u5957\u51fd\u6570\u5f0f\u7684\u8bbe\u8ba1\uff0c\u57fa\u4e8e\u539f\u5b50\u7684\u6570\u636e\u6765\u589e\u5f3a\u5c31\u597d<br \/>const tableProps = useTable(list);<br \/>const propsWithSelection = useSelection(tableProps);<br \/>const propsWithSort = useSort(propsWithSelection);<\/p>\n<p>\u8fd9\u6837\u751a\u81f3\u53ef\u4ee5\u5f88\u5feb\u901f\u5730\u6784\u5efa\u51fa\u9002\u5408\u81ea\u5df1\u7684 hook\uff1a<br \/>const useOwnTable = compose(useTable, useSelection, useSort);<\/p>\n<p>\u4efb\u4f55\u4e00\u4e2a\u4e1c\u897f\uff0c\u52a0\u4e0a\u63d2\u4ef6\u5c31\u662f\u5728\u589e\u52a0\u6982\u5ff5\uff0c\u63d2\u4ef6\u4e0d\u662f\u4e00\u4e2a\u516c\u8ba4\u7684\u903b\u8f91\uff0c\u6bcf\u4e00\u4e2a\u63d2\u4ef6\u7cfb\u7edf\u7684\u5b9e\u73b0\u548c\u8bbe\u8ba1\u90fd\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u8ba9\u4eba\u53bb\u7406\u89e3\u6210\u672c\u5e76\u4e0d\u4f4e                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108516\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : monkindey <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @otakustay plugin \u5176\u5b9e\u5c31\u662f\u4e00\u4e2a hook\uff0c\u53ea\u662f\u4e00\u4e2a\u9ad8\u7ea7 hook\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u5c5e\u6027\u800c\u5df2\u3002\u800c\u4e14\u591a\u9009\u3001\u6392\u5e8f\u90fd\u662f\u4f9d\u8d56\u67e5\u8be2\u6d41\u7a0b\u7684\uff0c\u5982\u679c\u4f60\u53ea\u662f\u5173\u5fc3 props \u7684\u8bdd\uff0c\u6ca1\u529e\u6cd5\u4e00\u4e0b\u5c31\u5b8c\u6210\u4e00\u4e2a\u529f\u80fd\uff0c\u6bd4\u5982\u591a\u9009\u52fe\u9009\u7684\u65f6\u5019\uff0c\u91cd\u65b0\u70b9\u51fb\u67e5\u8be2\u4f1a\u6e05\u7a7a\u6389\u52fe\u9009\u7684\u503c\uff0c\u6392\u5e8f\u4e5f\u662f\u4e00\u6837\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5176\u5b9e useTable \u662f\u5177\u5907\u63d2\u4ef6\u5408\u5e76\u7684\u80fd\u529b\uff0c\u6bcf\u4e00\u4e2a\u63d2\u4ef6\u4e5f\u662f\u4e00\u4e2a hook\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3 useTable \u5c31\u662f\u4e00\u4e2a compose\uff0cuseTable \u3001useSelction \u3001useSort \u662f\u4e00\u4e2a\u63d2\u4ef6\u3002\u4e5f\u5c31\u662f\u4f60\u7684\u7406\u89e3\uff1a<\/p>\n<p>const useOwnTable = compose(useTable, useSelection, useSort); <\/p>\n<p>\u76f8\u5f53\u4e8e<\/p>\n<p>const useOwnTable = useTable(useSelection, useSort)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108517\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : monkindey <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @otakustay \u63d2\u4ef6\u4f60\u53ef\u4ee5\u7406\u89e3\u662f\u589e\u52a0\u4e00\u4e2a\u6982\u5ff5\uff0c\u4f46\u662f\u91cc\u9762\u7528\u7684\u4e1c\u897f\u90fd\u4e0d\u662f\u65b0\u6982\u5ff5\uff0c\u90fd\u662f\u4e00\u4e9b\u4e1a\u754c\u6d41\u884c\u7684\u6982\u5ff5\u5408\u5e76\u5728\u4e00\u8d77\u3002\u56e0\u4e3a\u6211\u4eec\u8981\u5199\u4e00\u4e2a\u5730\u65b9\u5c31\u53ef\u4ee5\u89e3\u51b3\u4e00\u4e2a\u529f\u80fd\u7684\uff0c\u4e0d\u9700\u8981\u6211\u52a0\u4e00\u4e2a\u591a\u9009\u7684\u529f\u80fd\u6216\u8005\u6392\u5e8f\u7684\u529f\u80fd\u90fd\u8981\u7528 useState \u72b6\u6001\u7ba1\u7406\uff0c\u7136\u540e\u8bbe\u7f6e props\uff0c\u7136\u540e\u5728\u8bf7\u6c42\u7684\u94fe\u8def\u4e2d\u8fd8\u8981\u53bb\u6e05\u9664\u52fe\u9009\u9879\uff0c\u4f60\u4f1a\u53d1\u73b0\u4ee3\u7801\u5199\u8d77\u6765\u5c31\u5f88\u7e41\u7410\uff0c\u7279\u522b\u662f\u5f53\u4f60\u8d1f\u8d23\u5f88\u591a\u7c7b\u4f3c\u9875\u9762\u7684\u65f6\u5019\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108518\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : otakustay <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt; \u800c\u4e14\u591a\u9009\u3001\u6392\u5e8f\u90fd\u662f\u4f9d\u8d56\u67e5\u8be2\u6d41\u7a0b\u7684\uff0c\u5982\u679c\u4f60\u53ea\u662f\u5173\u5fc3 props \u7684\u8bdd\uff0c\u6ca1\u529e\u6cd5\u4e00\u4e0b\u5c31\u5b8c\u6210\u4e00\u4e2a\u529f\u80fd<\/p>\n<p>\u6211\u4f1a\u9009\u62e9\u5148\u5f04\u4e00\u4e2a useTableParams \u7684\u4e1c\u897f\u6765\u7ec4\u88c5\u53c2\u6570\uff0cuseTableXxxParams \u8ffd\u52a0\u53c2\u6570<\/p>\n<p>\u7b97\u662f\u8bbe\u8ba1\u7406\u5ff5\u4e0a\u7684\u4e0d\u540c\u5427\uff0c\u6211\u6bd4\u8f83\u559c\u6b22\u201c\u5982\u65e0\u5fc5\u8981\uff0c\u52ff\u589e\u6982\u5ff5\u201d\u7684\u73a9\u6cd5                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3108519\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : monkindey <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @otakustay \u989d\u989d\uff0c\u540c\u610f\u4f60\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u6211\u4e5f\u559c\u6b22\u7b80\u5355\u3002\u6211\u4e5f\u601d\u8003\u5f88\u4e45\uff0c\u8bf4\u670d\u5f88\u591a\u4eba\uff0c\u6574\u4e00\u4e2a\u8bbe\u8ba1\u5e76\u6ca1\u6709\u52a0\u6982\u5ff5\uff0c\u63d2\u4ef6\u5176\u5b9e\u4e00\u4e2a hook\uff0c\u91cc\u9762\u6709 middleware \u8fd8\u6709 compose \u90fd\u662f\u4e1a\u754c\u901a\u7528\u65b9\u6848\uff0c\u53ea\u662f\u5728\u8fd9\u91cc\u628a\u5b83\u4eec\u5408\u5728\u4e00\u8d77\u3002<\/p>\n<p>\u7ec4\u88c5\u53c2\u6570\u53ea\u662f\u4e00\u90e8\u5206\uff0c\u8fd8\u6709\u5728\u67e5\u8be2\u524d\u505a\u4e8b\u60c5\uff0c\u5728\u67e5\u8be2\u540e\u505a\u4e8b\u60c5\uff0c\u6bd4\u5982\u6211\u4eec\u8fd9\u8fb9\u6709\u4eba\u5b9e\u73b0\u4e00\u4e2a\u670d\u52a1\u7aef\u9a71\u52a8\u7684\u63d2\u4ef6\uff0c\u8fd8\u53ef\u4ee5\u62e6\u622a response \u505a\u683c\u5f0f\u5316\u3002<\/p>\n<p>\u56e0\u4e3a\u6211\u4e0d\u77e5\u9053\u4f60\u4eec\u6709\u6ca1\u6709\u505a\u8fc7\u4e2d\u53f0\u9875\u9762\uff0c\u53ef\u80fd\u4ee3\u5165\u611f\u6bd4\u8f83\u5f31\u3002\u4f60\u63d0\u7684\u95ee\u9898\u6211\u4eec\u8fd9\u8fb9\u5728\u5bf9\u8fd9\u4e2a\u65b9\u6848\u7684\u65f6\u5019\u4e5f\u63d0\u51fa\u6765\u8fc7\uff0c\u4f46\u662f\u6700\u540e\u90fd\u8ba4\u540c\u4e86\u3002\u5982\u679c\u4f60\u60f3\u8fdb\u4e00\u6b65\u4ea4\u6d41\u7684\u8bdd\uff0c\u53ef\u4ee5\u52a0\u6211\u5fae\u4fe1 atob(&#8216;bW9ua2luZGV5&#8217;) ( console \u6267\u884c\u4e0b )                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>ahooks \u2022 useTable&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\/149200"}],"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=149200"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149200\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149200"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}