1.0.0-rc.16 • Published 3 months ago

@exobase/use-path-parser v1.0.0-rc.16

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

title: 'usePathParser' description: 'A hook to parse url path params'

group: 'Hooks'

An Exobase hook that will parse path params and set them on the request. This hook is a bit unusual because it makes a change to the request to add the parsed path parameters. There are not many cases where you'll need this. Either

  • The framework + root hook your running will parse the path params (Next.js is an example of this) and set them in the request
  • The useRouter hook will parse the params and set them in the request

This hook does not validate the params, it only looks at the template path you give and the path of the current request and parses out the variable segments. To do validation, use usePathParams.

Install

yarn add @exobase/use-path-parser
# or
yarn add @exobase/hooks

Import

import { usePathParser } from '@exobase/use-path-parser'
// or
import { usePathParser } from '@exobase/hooks'

Usage

import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useLambda } from '@exobase/use-lambda'
import { usePathParser } from '@exobase/use-path-parser'

export const findBookById = async (props: Props) => {
  console.log(props.request.params) // { id: 'art-of-war' }
}

export default compose(
  useLambda(),
  usePathParser('/library/books/{id}')
  findBookById
)
1.0.0-rc.16

3 months ago

1.0.0-rc.15

3 months ago

1.0.0-rc.13

3 months ago

1.0.0-rc.14

3 months ago

1.0.0-rc.11

1 year ago

1.0.0-rc.9

1 year ago

1.0.0-rc.8

1 year ago

1.0.0-rc.10

1 year ago

1.0.0-rc.7

1 year ago

1.0.0-rc.6

1 year ago

1.0.0-rc.5

1 year ago

1.0.0-rc.4

1 year ago

1.0.0-rc.3

1 year ago

1.0.0-rc.2

1 year ago

1.0.0-rc.1

1 year ago