Last active
February 14, 2019 18:49
-
-
Save ryanflorence/b8df20bbd4aa7dbbc73640db0954c374 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
let pagesByLocationKey = {}; | |
function ListPage(props) { | |
const { key } = props.location | |
const [page, setPage] = useState(pagesByLocationKey[key] ? pagesByLocationKey[key].page : 0) | |
const [data, setData] = useState(pagesByLocationKey[key] ? pagesByLocationKey[key].data : null) | |
useEffect(() => { | |
if (!data) { | |
fetchPage(page).then(data => { | |
setData(data) | |
pagesByLocationKey[key] = { page, data } | |
}) | |
} | |
}, [page]) | |
return ( | |
<div> | |
<ul/> | |
<button onClick={() => { | |
setPage(page + 1) | |
}}>Next Page</button> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment