{"id":3663,"date":"2022-09-24T11:57:28","date_gmt":"2022-09-24T02:57:28","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3663"},"modified":"2022-09-27T23:29:25","modified_gmt":"2022-09-27T14:29:25","slug":"%e3%80%90react%e3%80%91react-window-fixed-size-list-%e3%83%ac%e3%82%b9%e3%83%9d%e3%83%b3%e3%82%b7%e3%83%96","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3663","title":{"rendered":"\u3010React\u3011react-window Fixed Size List \u30ec\u30b9\u30dd\u30f3\u30b7\u30d6"},"content":{"rendered":"\n<p>Fixed Size List \u3092\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u524d\u56de\u306f\u4ee5\u4e0b\u3092\u53c2\u7167\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u524d\u56de<\/span>\n<p><\/p>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=3656\" rel=\"noopener\" target=\"_blank\">\u3010React\u3011react-window Fixed Size List<\/a><\/p>\n<\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n\n\n\n<p>json\u30c7\u30fc\u30bf\u304b\u3089\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3092\u53d6\u5f97\u3057\u3066\u3001\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"240\" src=\"https:\/\/dennie.tokyo\/it\/wp-content\/uploads\/2022\/09\/FixedSizeList_\u30ec\u30b9\u30db\u309a\u30f3\u30b7\u30d5\u3099.gif\" alt=\"\" class=\"wp-image-3757\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u5b9f\u88c5<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">imgPathList.json (\u30a4\u30f3\u30d7\u30c3\u30c8\u30c7\u30fc\u30bf)<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-json\" data-lang=\"JSON\"><code>{\n    &quot;imgPathList&quot; : [\n        &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/P1014659.jpg&quot;,\n        &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/P1014660.jpg&quot;,\n        &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/P1014661.jpg&quot;,\n        &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/P1014662.jpg&quot;\n    ]\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>import &#39;.\/App.css&#39;;\nimport React, { useLayoutEffect , useState} from &#39;react&#39;;\nimport {FixedSizeList} from &#39;react-window&#39;;\nimport ImgPathList from &#39;.\/imgPathList.json&#39;;\n\nfunction App() {\n\n  const [width, setWidth] = useState(0);\n  const [height, setHeight] = useState(0);\n  \n  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u7e26\u306e\u9577\u3055\n  const orgItemSizeHigt = 576;\n\n  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u6a2a\u306e\u9577\u3055\n  const orgItemSizeWith = 1024;\n\n  \/\/ \u30ea\u30b9\u30c8\u306e\u5e45(0\u301c1\u3067\u8a2d\u5b9a\u3059\u308b\u3002ex)0.8 \u306f\u5e4580%)\n  const listWidth = 0.8;\n\n  \/\/ \u30ea\u30b9\u30c8\u30a2\u30a4\u30c6\u30e0\u306e\u9ad8\u3055\n  let listItemHeight = (width * listWidth) * (orgItemSizeHigt \/ orgItemSizeWith);\n\n  const resize = () =&gt; {\n    setWidth(window.innerWidth);\n    setHeight(window.innerHeight);\n  }\n\n  useLayoutEffect(()=&gt;{\n    window.addEventListener(&quot;resize&quot;, resize);\n    resize();\n  },[])\n\n  const RenderItem = ({index, style}) =&gt; {\n    return (\n      &lt;div style={style}&gt;\n        &lt;img src={ImgPathList.imgPathList[index]} width= {&quot;100%&quot;}\/&gt;\n      &lt;\/div&gt;\n    );\n  }\n\n  return (\n    &lt;FixedSizeList\n      height={height}\n      width={width * listWidth}\n      itemSize={listItemHeight}\n      itemCount={ImgPathList.imgPathList.length}\n    &gt;\n      {RenderItem}\n    &lt;\/FixedSizeList&gt;\n  );\n}\n\nexport default App;<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u7279\u306b\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fixed Size List \u3092\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":2596,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-3663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3663"}],"version-history":[{"count":4,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3663\/revisions"}],"predecessor-version":[{"id":3758,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3663\/revisions\/3758"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/2596"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}