@exobase/use-query-string
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.26 • Public • Published

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.

Install

yarn add @exobase/use-query-string
# or
yarn add @exobase/hooks

Import

import { useQueryString } from '@exobase/use-query-string'
// or
import { useQueryString } from '@exobase/hooks'

Usage

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
)

Readme

Keywords

none

Package Sidebar

Install

npm i @exobase/use-query-string

Weekly Downloads

74

Version

1.0.0-rc.26

License

MIT

Unpacked Size

17.3 kB

Total Files

17

Last publish

Collaborators

  • rayepps