Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jackall3n/next-query

A Next.js hook designed to parse and return query-string params on every render, even on load
https://github.com/jackall3n/next-query

Last synced: 4 days ago
JSON representation

A Next.js hook designed to parse and return query-string params on every render, even on load

Awesome Lists containing this project

README

        

# next-query 🔎


NPM Version
Package License
NPM Downloads

## Blurb

A hook for Next.js which can parse and return a query-string object, even on load.

## Installation

```shell
npm install next-query
```
```shell
yarn add next-query
```

## Usage

### Basic

```typescript
import useQuery from 'next-query';

function Page() {
// Returns => { id: string | string[] };
const { id } = useQuery();

...
}
```

### Typed

```typescript
import useQuery from 'next-query';

function Page() {
// Return Type => { id: string };
const { id } = useQuery<{ id: string }>();

...
}
```

### Parsed

```typescript
import useQuery from 'next-query';

function Page() {
// Return Type => { id: number };
const { id } = useQuery({ id: Number });

...
}
```

See Supported Parse Types for more

### Arrays

```typescript
import useQuery from 'next-query';

function Page() {
// Return Type => { ids: number[] };
const { ids } = useQuery({ ids: [Number] });

...
}
```

### Complex

```typescript
import useQuery from 'next-query';

function Page() {
// Return Type => { id: number, selected: boolean };
const { ids, selected } = useQuery({ id: Number, selected: Boolean });

...
}
```

## API

### Supported Parse Types

```typescript
String | Boolean | Number
```