Last active
February 1, 2021 11:21
-
-
Save tolumide-ng/78453b76c7a82512eb2e950875636a8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
export const DisplayProductsComponent = () =>< { | |
const {createScrollObserver, converge, setConverge} = useIntersectionObserver(); | |
const [product, setProduct] = React.useState<ProductDef>(undefined); | |
const loadMoreRef = React.useRef<HTMLDivElement>(null); | |
let scrollObserver = createScrollObserver(); | |
React.useEffect(() => { | |
// other conditions/cases | |
if(loadMoreRef?.current) { | |
scrollObserver.observe(loadMoreRef.current); | |
} | |
}, [product]) | |
React.useEffect(() => { | |
if(converge && whateverOtherCondition){ | |
loadMoreFunc(); | |
// Return converge back to it's original state, so that we can be notified when there is another convergence | |
// as the user scrolls after more content has been loaded | |
setConverge(false); | |
} | |
}, [converge]); | |
function loadMore(){ | |
fetch(...); | |
} | |
return ( | |
<> | |
... | |
<div ref={loadMoreRef}></div> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment