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

1.0.0-rc.3 • Public • Published

Provides a hook to parse and validate query string values in the request.

Install

Yarn

yarn add @exobase/use-query-args

or install useQueryArgs with all other Exobase provided hooks:

yarn add @exobase/hooks

Usage

import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useQueryArgs } from '@exobase/use-query-args'
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(),
  useQueryArgs(z => ({
    id: zod.string(),
    format: zod.string()
  })),
  getAccount
)

Readme

Keywords

none

Package Sidebar

Install

npm i @exobase/use-query-args

Weekly Downloads

0

Version

1.0.0-rc.3

License

MIT

Unpacked Size

16 kB

Total Files

17

Last publish

Collaborators

  • rayepps