Skip to content

wrong url after refresh page #392

@veffev

Description

@veffev

I using next-usequerystate library with Next Js 13, my problem is that when I refresh the page the state on url is lost . This is the url:

localhost:3000/?page=1&genres=tree

When I refresh the page the URL will be :

localhost:3000/

But if I check with console.log(page) and console.log(genres) my states I see the data

I think that the URL started on server component so when my client component start with the status the URL is already setted.

This is my code:

'use client'
import React from 'react'
import {
  useQueryState,
  parseAsArrayOf,
  parseAsString,
  parseAsInteger,
} from 'next-usequerystate'
import Filters from './Filters'
import ListItem from './ListItem'

const ListProvider = () => {
  const [genres, setGenres] = useQueryState(
    'genres',
    parseAsArrayOf(parseAsString).withDefault([])
  )
  const [pageIndex, setPageIndex] = useQueryState(
    'page',
    parseAsInteger.withDefault(1)
  )

  return (
    <>
      <Filters genres={genres} setGenres={setGenres} />
      <ListItem
        genresFilters={genres}
        setGenres={setGenres}
        pageIndex={pageIndex}
        setPageIndex={setPageIndex}
      />
    </>
  )
}

export default ListProvider

I tried to avoid the problem with this solution :

useEffect(() => { setGenres(genres) setPageIndex(pageIndex) }, [])

I don't think is a good solution, but it works.

is there anyone having the same problem? Can you help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnext.jsIssue is related to Next.js internals rather than this library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions