Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): exports parseSearchParams #10185

Merged
merged 2 commits into from
Dec 26, 2024

Conversation

jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented Dec 26, 2024

As pointed out in #10164, parsing a where query from search params is not exactly straightforward. Internally we rely on the qs module for this, but it comes with a couple small nuances that are undocumented, like the need to stringify them and specify depth. To standardize this, we use a parseSearchParams utility internally that accepts the URLSearchParams object that the useSearchParams() hook returns from next/navigation. This PR exports that function for reuse and adds JSDocs accordingly. Usage looks something like this:

'use client'
import { useSearchParams } from 'next/navigation'
import { parseSearchParams } from '@payloadcms/ui'

function MyComponent() {
  const searchParams = useSearchParams()
  const parsedSearchParams = parseSearchParams(searchParams)
}

@jacobsfletch jacobsfletch marked this pull request as ready for review December 26, 2024 20:40
@jacobsfletch jacobsfletch linked an issue Dec 26, 2024 that may be closed by this pull request
@jacobsfletch jacobsfletch merged commit 5d3b816 into main Dec 26, 2024
73 checks passed
@jacobsfletch jacobsfletch deleted the chore/export-parse-search-params branch December 26, 2024 21:02
Copy link
Contributor

🚀 This is included in version v3.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing "where" field in searchParams in CustomComponent
1 participant