Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mskelton/use-strict-params
Strictly typed params for React router.
https://github.com/mskelton/use-strict-params
params react react-router strict typescript
Last synced: 30 days ago
JSON representation
Strictly typed params for React router.
- Host: GitHub
- URL: https://github.com/mskelton/use-strict-params
- Owner: mskelton
- License: isc
- Created: 2023-12-01T00:27:17.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-06-24T15:16:58.000Z (5 months ago)
- Last Synced: 2024-10-14T00:04:54.117Z (about 1 month ago)
- Topics: params, react, react-router, strict, typescript
- Language: TypeScript
- Homepage: https://npm.im/use-strict-params
- Size: 174 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# use-strict-params
[![Build status](https://github.com/mskelton/use-strict-params/workflows/Build/badge.svg)](https://github.com/mskelton/use-strict-params/actions)
[![npm version](https://img.shields.io/npm/v/use-strict-params)](https://www.npmjs.com/package/use-strict-params)Strictly typed params for React router.
## Installation
### npm
```sh
npm install use-strict-params
```### Yarn
```sh
yarn add use-strict-params
```### pnpm
```sh
pnpm add use-strict-params
```### bun
```sh
bun add use-strict-params
```## Usage
### `useStrictParams`
A typed variant of `useParams`. The following types are supported:
- `String`
- `Number`
- `Boolean`
- `Date````typescript
const { userId } = useStrictParams({ userId: Number })
```### `useStrictSearchParams`
A typed variant of `useSearchParams`. The following types are supported:
- `String`
- `Number`
- `Boolean`
- `Date````typescript
const { query } = useStrictSearchParams({ query: String })
```### `Optional`
Marks a type as optional which will change the return type to allow `null`.
```typescript
const { query } = useStrictSearchParams({ query: Optional(String) })
```