generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 254
Closed
Labels
bugSomething isn't workingSomething isn't workingnext.jsIssue is related to Next.js internals rather than this libraryIssue is related to Next.js internals rather than this library
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingnext.jsIssue is related to Next.js internals rather than this libraryIssue is related to Next.js internals rather than this library