Skip to content

Commit c8c91a1

Browse files
[Add] lazy load component
1 parent 2535086 commit c8c91a1

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"react": "^16.12.0",
2828
"react-dom": "^16.12.0",
2929
"react-helmet": "^5.2.1",
30-
"react-image-lightbox": "^5.1.1"
30+
"react-image-lightbox": "^5.1.1",
31+
"react-lazyload": "^2.6.7"
3132
},
3233
"devDependencies": {
3334
"eslint-config-prettier": "^6.10.0",

src/pages/index.js

+29-26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./index.scss"
44
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
55
import { faSearch, faTimes, faFilter } from "@fortawesome/free-solid-svg-icons"
66
import { activityTypes, normalizeActivityType } from "../lib/normalize"
7+
import LazyLoad from "react-lazyload"
78

89
import Layout from "../components/layout"
910
import Fluid200 from "../components/Fluid200"
@@ -194,33 +195,35 @@ const IndexPage = () => {
194195
<ul className="org-list">
195196
{filteredOrgs.map(({ node: org }) => (
196197
<li className="org-list__item" key={org.primaryKey}>
197-
<Link to={`/org/${org.primaryKey}`}>
198-
<figure className="org-list__item__poster">
199-
<Fluid200 url={org.posterImageUrls[0]} alt="" />
200-
<figcaption>
201-
<h2 className="org-list__item__name">{org.name}</h2>
202-
<p className="org-list__item__activity-introduce">
203-
{org.activityIntroduce.slice(0, 100) + "..."}
204-
</p>
205-
</figcaption>
206-
</figure>
207-
</Link>
208-
209-
<div // スマホ用
210-
className="org-list__item__sp-caption"
211-
onClick={() => {
212-
if (lastTouchedItem === org.primaryKey)
213-
navigate(`/org/${org.primaryKey}`)
214-
setLastTouchedItem(org.primaryKey)
215-
}}
216-
>
217-
<div className="org-list__item__sp-caption__name">
218-
{org.name}
219-
</div>
220-
<div className="org-list__item__sp-caption__activity-introduce">
221-
{org.activityIntroduce.slice(0, 100) + "..."}
198+
<LazyLoad offset={200} once>
199+
<Link to={`/org/${org.primaryKey}`}>
200+
<figure className="org-list__item__poster">
201+
<Fluid200 url={org.posterImageUrls[0]} alt="" />
202+
<figcaption>
203+
<h2 className="org-list__item__name">{org.name}</h2>
204+
<p className="org-list__item__activity-introduce">
205+
{org.activityIntroduce.slice(0, 100) + "..."}
206+
</p>
207+
</figcaption>
208+
</figure>
209+
</Link>
210+
211+
<div // スマホ用
212+
className="org-list__item__sp-caption"
213+
onClick={() => {
214+
if (lastTouchedItem === org.primaryKey)
215+
navigate(`/org/${org.primaryKey}`)
216+
setLastTouchedItem(org.primaryKey)
217+
}}
218+
>
219+
<div className="org-list__item__sp-caption__name">
220+
{org.name}
221+
</div>
222+
<div className="org-list__item__sp-caption__activity-introduce">
223+
{org.activityIntroduce.slice(0, 100) + "..."}
224+
</div>
222225
</div>
223-
</div>
226+
</LazyLoad>
224227
</li>
225228
))}
226229
</ul>

0 commit comments

Comments
 (0)