Skip to content

Is it possible to dynamically set createSearchParamsCache default values? #736

Discussion options

You must be logged in to vote

Not out of the box, because the cache reference needs to be available for nested components to refer to, and dynamic values will likely be obtained during a page render (via cookies I assume).

However, you can update that reference at render time before parsing, with custom default values, and that would make it available for nested components. I tested this quickly in development mode using separate files and it seemed to work, YMMV.

import {
  createSearchParamsCache,
  parseAsInteger,
  parseAsString,
  type SearchParams
} from 'nuqs/server'

type PageProps = {
  searchParams: Promise<SearchParams>
}

type ConfirmBookingSearchParams = {
  email: string
  type: string
  bayHours: number
  

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by franky47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants