1.0.0-rc.17 • Published 1 year ago
@exobase/use-path-parser v1.0.0-rc.17
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
useRouterhook 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/hooksImport
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.17
1 year ago
1.0.0-rc.16
2 years ago
1.0.0-rc.15
2 years ago
1.0.0-rc.13
2 years ago
1.0.0-rc.14
2 years ago
1.0.0-rc.11
3 years ago
1.0.0-rc.9
3 years ago
1.0.0-rc.8
3 years ago
1.0.0-rc.10
3 years ago
1.0.0-rc.7
3 years ago
1.0.0-rc.6
3 years ago
1.0.0-rc.5
3 years ago
1.0.0-rc.4
3 years ago
1.0.0-rc.3
3 years ago
1.0.0-rc.2
3 years ago
1.0.0-rc.1
3 years ago