Skip to content

Commit

Permalink
feat: Freeze cache after parsing and return it
Browse files Browse the repository at this point in the history
This allows accessing the parsed values straight from the
page component. Freezing also ensures the object reference
stays immutable for the whole duration of the page render.
  • Loading branch information
franky47 committed Nov 16, 2023
1 parent d20e01e commit 5738335
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/next-usequerystate/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export function createSearchParamCache<
const c = getCache()
for (const key in parsers) {
const parser = parsers[key]!
c[key as Keys] = parser.parseServerSide(searchParams[key])
c[key] = parser.parseServerSide(searchParams[key])
}
return Object.freeze(c)
}
function getSearchParam<Key extends keyof Parsers>(
key: Key
Expand Down

0 comments on commit 5738335

Please sign in to comment.