title: 'useQueryString' description: 'A hook to parse and validate a request query string' group: 'Hooks' badge: 'Validation'
Provides a hook to parse and validate query string values in the request.
yarn add @exobase/use-query-string
# or
yarn add @exobase/hooks
import { useQueryString } from '@exobase/use-query-string'
// or
import { useQueryString } from '@exobase/hooks'
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useQueryString } from '@exobase/use-query-string'
import { useLambda } from '@exobase/use-lambda'
type Args = {
id: number
format: 'basic' | 'detailed'
}
const getAccount = async ({ args }: Props) => {
const { id, format } = args
const account = await db.accounts.find(id)
return format === 'basic'
? mappers.Account.basic(account)
: mappers.Account.detailed(account)
}
export default compose(
useLambda(),
useQueryString(z => ({
id: zod.string(),
format: zod.string()
})),
getAccount
)