{"id":3688,"date":"2022-09-25T14:45:49","date_gmt":"2022-09-25T05:45:49","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3688"},"modified":"2022-09-27T21:25:49","modified_gmt":"2022-09-27T12:25:49","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","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3688","title":{"rendered":"\u3010React\u3011react-window Fixed Size Grid \u30ec\u30b9\u30dd\u30f3\u30b7\u30d6"},"content":{"rendered":"\n<p>Fixed Size Grid \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 Fixed Size Grid \u306b\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3057\u307e\u3057\u305f\u3002\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\">\u53c2\u7167<\/span>\n<p><\/p>\n<p><a href=\"https:\/\/dennie.tokyo\/it\/?p=3671\" rel=\"noopener\" target=\"_blank\">\u3010React\u3011react-window Fixed Size Grid \u4efb\u610f\u306e\u30c7\u30fc\u30bf\u8868\u793a<\/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\/PhotoGallery.gif\" alt=\"\" class=\"wp-image-3692\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0<\/h1>\n\n\n\n<p>\u524d\u56de\u306f App\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u307f\u3067\u4f5c\u6210\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u65b0\u305f\u306bPhotoGallery\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\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        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014659.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014660.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014661.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014662.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014662.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014663.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014664.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014665.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014666.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014666.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014667.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014668.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014669.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014670.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014670.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014671.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014672.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014673.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014674.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014674.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014675.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014676.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014677.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014678.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014678.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014681.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014684.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014685.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014686.jpg&quot;\n        ],\n        [\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014681.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014684.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014685.jpg&quot;,\n            &quot;https:\/\/dennie.tokyo\/norway\/img\/photos\/square\/P1014686.jpg&quot;\n        ]\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;;\n\/\/ import &#39;.\/dennie.css&#39;;\nimport React from &#39;react&#39;;\nimport PhotoGallery from &#39;.\/PhotoGallery&#39;;\nimport imagePathList from &#39;.\/imgPathList.json&#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  \/\/ \u5199\u771f(\u30b5\u30e0\u30cd\u30a4\u30eb)\u306e\u8868\u793a\n  const RenderItem = ({columnIndex, rowIndex, style, data}) =&gt; {\n    return (\n      &lt;div style={{...style}}&gt;\n         &lt;img src={data[rowIndex][columnIndex]} width={&quot;100%&quot;}\/&gt;\n      &lt;\/div&gt;\n    );\n  }\n\n  return (\n    &lt;&gt;\n    &lt;PhotoGallery \n      imgPathList = {imagePathList.imgPathList}\n      renderItem = {RenderItem} \n      columnCount = {columnCount}\n      tableWidth = {tableWidth}\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<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  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  return (\n    &lt;FixedSizeGrid\n      className = {className}\n      columnCount = {columnCount}\n      columnWidth = {colWidth}\n      height = {height}\n      width = {width * tableWidth}\n      rowCount = {imgPathList.length}\n      rowHeight = {colHeight}\n      itemData = {imgPathList}\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<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<h1 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h1>\n\n\n\n<p>\u30b5\u30e0\u30cd\u30a4\u30eb\u30d1\u30b9\u4e00\u89a7\u304c\u56fa\u5b9a\u306a\u306e\u3067\u3001\u6b21\u56de\u306f\u52d5\u7684\u306b\u30d1\u30b9\u4e00\u89a7\u3092\u66f4\u65b0\u3059\u308b\u3088\u3046\u306a\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"title_box\"><span class=\"box-title\">\u6b21\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","protected":false},"excerpt":{"rendered":"<p>Fixed Size Grid \u3092\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":5,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-3688","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\/3688","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=3688"}],"version-history":[{"count":13,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3688\/revisions"}],"predecessor-version":[{"id":3740,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3688\/revisions\/3740"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/5"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}