Next.js Discord

Discord Forum

query params aren't working before refresh

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
So weird issue here. I'm trying to do serverside pagination.

Frontend:
ts    if (props.prev > 0 || links.length == 25){
        let prevButton = <Link href={{pathname:"links", query:{after:props.prev}}}>Previous 25</Link>
        let nextButton = <Link href={{pathname:"links", query:{after:props.next}}}>next 25</Link>

        if (props.prev < 0){
            prevButton = <></>
        }

        if (links.length < 25){
            nextButton = <></>
        }
        nextAndPrevButtons = <>{prevButton}{nextButton}</>
        
    }

backend:
getServerSideProps({req, query}:any){
... 
after = parseInt(query.after as string)
....
let linkData:LinkWithViews[] = await prisma.generatedLink.findMany({
        skip:after,
        take:25,
        where:{
            userID:user.id
        },
  ...

So when I try this, what ends up happening is the URL changes, and "After" changes (as viewed by console.log) but the actual findmany collected by prisma appear to be the same. Then I refresh and everything works. So the issue basically is that it will appear to navigate to the new page/pagination index, gather the correct data, but the links are the same as before (you can click "next" a dozen times until after says 2000 or something and it will still be the same). So I'm seeing the page as if it had a previous pagination. But refreshing it will fix this problem.
Any idea what's going on here?

3 Replies

Northeast Congo LionOP
ok, looks like the state just isn't updating when I navigate this way. Any idea how to force the state to update?
esp from backend
Northeast Congo LionOP
Apparently you have to refresh to get the results of getServerSideProps to work. How am I supposed to do this then?