Implemented infinite scroll
This commit is contained in:
committed by
Vishnu Ks
parent
302806920c
commit
40d8e36880
13563
app/package-lock.json
generated
13563
app/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gatsby": "^2.15.36",
|
"gatsby": "^2.23.0",
|
||||||
"gatsby-image": "^2.2.27",
|
"gatsby-image": "^2.2.27",
|
||||||
"gatsby-plugin-manifest": "^2.2.21",
|
"gatsby-plugin-manifest": "^2.2.21",
|
||||||
"gatsby-plugin-offline": "^3.0.14",
|
"gatsby-plugin-offline": "^3.0.14",
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
import React from "react"
|
import React, { useState, useEffect } from "react"
|
||||||
|
|
||||||
import Layout from "../components/layout"
|
import Layout from "../components/layout"
|
||||||
import SEO from "../components/seo"
|
import SEO from "../components/seo"
|
||||||
import BookCard from "../components/bookcard"
|
import BookCard from "../components/bookcard"
|
||||||
|
|
||||||
|
function myFunction(data, end, setEnd) {
|
||||||
|
if (document.documentElement.clientHeight+document.documentElement.scrollTop===document.documentElement.scrollHeight) {
|
||||||
|
setEnd(end+4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default ({data}) => {
|
export default ({data}) => {
|
||||||
|
let [end, setEnd] = useState(4);
|
||||||
|
useEffect(()=>{
|
||||||
|
window.document.onscroll = () => myFunction(data, end, setEnd);
|
||||||
|
})
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<SEO title="Home" />
|
<SEO title="Home" />
|
||||||
<div className="flex flex-row flex-wrap">
|
<div className="flex flex-row flex-wrap">
|
||||||
{data.allBooksJson.edges.map(function(x) {
|
{data.allBooksJson.edges.map(function(x, index) {
|
||||||
return (
|
if(index<end){
|
||||||
<BookCard book={x.node} key={x.node.id} />
|
return (
|
||||||
)
|
<BookCard book={x.node} key={x.node.id} />
|
||||||
|
)
|
||||||
|
}
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user