{"id":3743,"date":"2022-09-27T22:25:49","date_gmt":"2022-09-27T13:25:49","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3743"},"modified":"2022-09-27T22:31:40","modified_gmt":"2022-09-27T13:31:40","slug":"%e3%80%90react%e3%80%91react-window-%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%9f%e5%86%99%e7%9c%9f%e3%82%ae%e3%83%a3%e3%83%a9%e3%83%aa%e3%83%bc-2","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3743","title":{"rendered":"\u3010React\u3011react-window \u3092\u4f7f\u7528\u3057\u305f\u5199\u771f\u30ae\u30e3\u30e9\u30ea\u30fc"},"content":{"rendered":"\n<p>\u81ea\u5206\u7528\u306e\u30e1\u30e2\u306b\u306a\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u5199\u771f\u30ae\u30e3\u30e9\u30ea\u30fc\u3092\u5b8c\u6210\u3055\u305b\u305f\u3044\u3068\u601d\u3044\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=3700\" rel=\"noopener\" target=\"_blank\">\u3010React\u3011react-window \u3092\u4f7f\u7528\u3057\u305f\u52d5\u7684\u30c6\u30fc\u30d6\u30eb<\/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>\u8868\u793a\u3059\u308b\u30b5\u30e0\u30cd\u30a4\u30eb\u306b\u30b9\u30bf\u30a4\u30eb\u3092\u5f53\u3066\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br>\u96a3\u308a\u5408\u3046\u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u9593\u306b\u30dc\u30fc\u30c0\u30fc\u3092\u5165\u308c\u3001\u5404\u30b5\u30e0\u30cd\u30a4\u30eb\u306b\u9593\u9694\u304c\u7a7a\u304f\u3088\u3046\u306b\u8868\u793a\u3055\u305b\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\/PhotoGallery-1.gif\" alt=\"\" class=\"wp-image-3748\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u5b9f\u88c5<\/h1>\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 &#39;.\/dennie.css&#39;;\nimport React from &#39;react&#39;;\nimport PhotoGallery from &#39;.\/PhotoGallery&#39;;\nimport ImgPathList from &#39;.\/ImgPathList&#39;;\n\nfunction App() {\n\n  \/\/ \u5217\u306e\u6570(1\u5217\u306b\u8868\u793a\u3059\u308b\u5199\u771f\u306e\u6570)\n  const columnCount = 4;\n\n  \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u5e45(0\u301c1\u3067\u8a2d\u5b9a\u3059\u308b\u3002ex)0.8 \u306f\u5e4580%)\n  const tableWidth = 0.8;\n\n  \/\/ \u30af\u30e9\u30b9\u540d(\u30aa\u30d7\u30b7\u30e7\u30f3)\n  \/\/ const className = &quot;dennie_container&quot;;\n\n  \/\/ \u7b2c\u4e00\u5f15\u6570\u304c\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3002\u7b2c\u4e8c\u5f15\u6570\u306f\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3092\u66f4\u65b0\u3059\u308b\u95a2\u6570\u3002\n  const [imagePathList, next] = ImgPathList(columnCount);\n\n  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u5de6\u9593\u9694\u3092\u6c7a\u3081\u308b\u3002\n  const thumbnailLeftBorder = &quot;5&quot;;\n\n  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u30c8\u30c3\u30d7\u9593\u9694\u3092\u6c7a\u3081\u308b\u3002\n  const thumbnailTopBorder = &quot;3&quot;;\n\n  \/\/ \u5199\u771f(\u30b5\u30e0\u30cd\u30a4\u30eb)\u306e\u8868\u793a\n  const RenderItem = ({columnIndex, rowIndex, style, data}) =&gt; {\n\n    \/\/ \u30c8\u30c3\u30d7\u30dc\u30fc\u30c0\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3002\n    let colBorder = {\n      &quot;border-top&quot;:  thumbnailTopBorder + &quot;px solid #ffffff&quot;\n    };\n\n    \/\/ \u5148\u982d\u884c\u306e\u30c8\u30c3\u30d7\u30dc\u30fc\u30c0\u30fc\u306f\u524a\u9664\u3059\u308b\u3002\n    if(rowIndex === 0){\n      delete colBorder[&quot;border-top&quot;];\n    }\n\n    \/\/ \u5148\u982d\u5217\u4ee5\u5916\u306e\u5834\u5408\u3001\u5de6\u30dc\u30fc\u30c0\u30fc\u3092\u8a2d\u5b9a\u3059\u308b\u3002\n    const colNumber = columnIndex % columnCount;\n    if(colNumber !== 0){\n      colBorder[&quot;border-left&quot;] = thumbnailLeftBorder + &quot;px solid #ffffff&quot;;\n    }\n\n    return (\n      &lt;div style={{...style}}&gt;\n         &lt;img src={data[rowIndex][columnIndex]} width={&quot;100%&quot;} style={colBorder}\/&gt;\n      &lt;\/div&gt;\n    );\n  }\n\n  return (\n    &lt;&gt;\n    &lt;PhotoGallery \n      imgPathList = {imagePathList}\n      renderItem = {RenderItem} \n      columnCount = {columnCount}\n      tableWidth = {tableWidth}\n      upDateList = {next}\n      thumbnailLeftBorder = {Number(thumbnailLeftBorder)}\n      \/\/ className = {className}\n      \/&gt;\n    &lt;\/&gt;\n  );\n}\n\nexport default App;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">dennie.css (\u4efb\u610f\u306a\u304f\u3066\u3082OK)<\/h2>\n\n\n\n<p>\u524d\u56de\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-css\" data-lang=\"CSS\"><code>.dennie_container {\n    border: 4px solid red;\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">PhotoGallery\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;.\/PhotoGallery.css&#39;;\nimport React, { useLayoutEffect , useState} from &#39;react&#39;;\nimport {FixedSizeGrid} from &#39;react-window&#39;;\n\nfunction PhotoGallery({\n  imgPathList = [],   \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\n  renderItem,         \/\/ \u30ab\u30e9\u30e0\u8868\u793a\n  columnCount,        \/\/ \u30ab\u30e9\u30e0\u6570\n  tableWidth = 1,       \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u5e45(1\u3067\u6a2a\u5e45\u30de\u30c3\u30af\u30b9)(\u30aa\u30d7\u30b7\u30e7\u30f3)\n  orgItemSizeWith = 1,  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u6a2a\u306e\u9577\u3055(\u30aa\u30d7\u30b7\u30e7\u30f3)\n  orgItemSizeHigt = 1,  \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u7e26\u306e\u9577\u3055(\u30aa\u30d7\u30b7\u30e7\u30f3)\n  upDateList = f =&gt; f,     \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u66f4\u65b0\u95a2\u6570(\u30aa\u30d7\u30b7\u30e7\u30f3)\n  thumbnailLeftBorder = 0, \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u306e\u9593\u9694\u3002\u30c6\u30fc\u30d6\u30eb\u306e\u9577\u3055\u306b\u8db3\u3059\u5fc5\u8981\u304c\u3042\u308b\u3002\n  className = &#39;container_center&#39;, \/\/ \u30af\u30e9\u30b9\u540d(\u30aa\u30d7\u30b7\u30e7\u30f3)\n}) {\n\n  \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u9ad8\u3055\u3001\u5e45\u3092\u4fdd\u6301\u3059\u308b\u3002\n  const [width, setWidth] = useState(0);\n  const [height, setHeight] = useState(0);\n  \n  \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u9ad8\u3055\u3001\u5e45\u3092\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u3002\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  \/\/ \u5217\u306e\u5e45\n  let colWidth = (width * tableWidth) \/ columnCount;\n\n  \/\/ \u5217\u306e\u9ad8\u3055(\u884c\u306e\u9ad8\u3055) \u5217\u306e\u5e45 * \u7e26\u6a2a\u6bd4\u7387\n  let colHeight = colWidth * (orgItemSizeHigt \/ orgItemSizeWith);\n\n  \/\/ \u30c7\u30fc\u30bf\u30ea\u30b9\u30c8\u306e\u9ad8\u3055\n  let listHeight = colHeight * imgPathList.length;\n\n  \/\/ \u30b9\u30af\u30ed\u30fc\u30eb\u30a4\u30d9\u30f3\u30c8\u3002\u30b9\u30af\u30ed\u30fc\u30eb\u4f4d\u7f6e\u3068\u30c7\u30fc\u30bf\u30ea\u30b9\u30c8\u306e\u9ad8\u3055\u3092\u5224\u5b9a\u3057\u3066\u3001\u30dc\u30c8\u30e0\u306b\u306a\u308a\u305d\u3046\u306a\u5834\u5408\u3001\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3092\u66f4\u65b0\u3059\u308b\u3002\n  const onScroll = ({\n    scrollTop,\n  }) =&gt; {\n    if(scrollTop &gt; listHeight - 1000){\n      upDateList();\n    }\n  }\n\n  return (\n    &lt;FixedSizeGrid\n      className = {className}\n      columnCount = {columnCount}\n      columnWidth = {colWidth}\n      height = {height}\n      width = {width * tableWidth + thumbnailLeftBorder}\n      rowCount = {imgPathList.length}\n      rowHeight = {colHeight}\n      itemData = {imgPathList}\n      onScroll = {onScroll}\n    &gt;\n      {renderItem}\n    &lt;\/FixedSizeGrid&gt;\n  );\n}\n\nexport default PhotoGallery;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">PhotoGallery.css<\/h2>\n\n\n\n<p>\u524d\u56de\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-css\" data-lang=\"CSS\"><code>.container_center {\n    margin: 0 auto;\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">ImgPathList \u30d5\u30c3\u30af<\/h2>\n\n\n\n<p>\u524d\u56de\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>import {useState} from &#39;react&#39;;\n\nfunction ImgPathList(columnCount = 5, parListCount = 10) {\n\n    \/\/ \u73fe\u5728\u306e\u30d1\u30b9\u540d\u306e\u30ab\u30a6\u30f3\u30c8\n    const [currentNumber, setCurrentNumber] = useState(1014659);\n\n    \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\n    const [imagePathList, setImagePathList] = useState([]);\n\n    const next = () =&gt; {\n\n        \/\/ \u65b0\u305f\u306b\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3092\u751f\u6210\u3059\u308b\u3002\n        let cnt = 0;\n        let imgPathList = [...Array(parListCount)].map(element =&gt; {\n            return [...Array(columnCount)].map(elem =&gt; {\n                const strCurrentNumber = String(currentNumber + cnt);\n                const imagePath = `https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P${strCurrentNumber}.jpg`;\n                cnt++;\n                return imagePath;\n            });\n        });\n\n        \/\/ \u73fe\u5728\u306e\u30d1\u30b9\u540d\u306e\u30ab\u30a6\u30f3\u30c8\u3092\u5897\u3048\u305f\u5206\u66f4\u65b0\u3059\u308b\u3002\n        setCurrentNumber(currentNumber + cnt - 1);\n        \n        \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u3092\u66f4\u65b0\u3059\u308b\u3002\n        setImagePathList(imagePathList.concat(imgPathList));\n    }\n    \n    return [imagePathList, next];\n}\n\nexport default ImgPathList;<\/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>\u81ea\u5206\u7528\u306e\u30e1\u30e2\u306b\u306a\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u3001\u5199\u771f\u30ae\u30e3\u30e9\u30ea\u30fc\u3092\u5b8c\u6210\u3055\u305b\u305f\u3044\u3068\u601d\u3044\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-3743","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\/3743","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=3743"}],"version-history":[{"count":3,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3743\/revisions"}],"predecessor-version":[{"id":3749,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3743\/revisions\/3749"}],"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=3743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}