Load More Pagination using Prisma, Urql & React? #1550
-
I am following this tutorial → https://blog.logrocket.com/pagination-in-graphql-with-prisma-the-right-way/ In the end, there is a Load More based pagination that looks like: I tried implementing it like: import React from 'react'
import { useQuery } from 'urql'
import { Card } from '../components/index'
import {
GET_ALL_ACQUISITIONS,
GET_ACQUISITIONS_BY_PRICE,
} from '../graphql/index'
export const AcquisitionList = ({
minPrice,
maxPrice,
undisclosed,
sortByDescPrice,
sortByAscStartupName,
}) => {
const [skip, setSkip] = React.useState(0)
const [result, reexecuteQuery] = useQuery({
query: GET_ACQUISITIONS_BY_PRICE,
variables: {
minPrice,
maxPrice,
undisclosed,
sortByDescPrice,
sortByAscStartupName,
skip,
take: 20,
},
})
const { data, fetching, error } = result
if (fetching) return <p className="mt-10 text-4xl text-center">Loading...</p>
if (error)
return (
<p className="mt-10 text-4xl text-center">Oh no... {error.message}</p>
)
return (
<>
<div className="flex flex-wrap justify-center mt-10">
{data.getAcquisitionsByPrice.map((startup, i) => {
return <Card key={i} startup={startup} index={i} />
})}
</div>
<div className="flex justify-center">
<button onClick={() => setSkip(skip + 20)}>Load More...</button>
</div>
</>
)
} But I lose all the previous state when I click How do I preserve the previous state while calling Prisma with the new query so I can show all the display Cards? So the first time, I have 20 cards, 2nd time when I load it should have 40 cards & so on... Currently, it only shows 20 cards at a time which is great if I had |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Depending on what cache you use there are a few options, one of them outlined in the documentation and two of them using your FE style of choice. In graphCache you can use a custom resolver You can also just use a
The above probably needs some tweaking, it's more meant to give you a rough idea. You can also use a VDOM based approach in case your
|
Beta Was this translation helpful? Give feedback.
Depending on what cache you use there are a few options, one of them outlined in the documentation and two of them using your FE style of choice.
In graphCache you can use a custom resolver
You can also just use a
usePagination
helper:The above probably needs some tweaking, it's more meant to give you a rough idea.
You can also use a VDOM based approac…