Skip to content

Commit

Permalink
docs: useDebounce hook (#98)
Browse files Browse the repository at this point in the history
Add documentation for useDebounce hook
  • Loading branch information
immois authored Jul 8, 2024
1 parent 95c3182 commit abfd2c2
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
"title": "useCounter",
"path": "/hooks/use-counter"
},
{
"title": "useDebounce",
"path": "/hooks/use-debounce"
},
{
"title": "useToggle",
"path": "/hooks/use-toggle"
Expand Down
72 changes: 72 additions & 0 deletions docs/en/use-debounce.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: useDebounce
description: Returns a debounced value of the provided value.
---

## Installation

Install the custom hook from your command line.

<Snippet pkg text='@raddix/use-debounce' />

## Usage

```tsx
import { useState } from 'react';
import { useDebounce } from 'ahooks';

export default function App() {
const [value, setValue] = useState<string>();
const debouncedValue = useDebounce(value, { wait: 500 });

return (
<div>
<input
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Typed value"
/>
<p>DebouncedValue: {debouncedValue}</p>
</div>
);
};
```

## API

### Parameters

<ApiTable
head={{
name: 'Parameters'
}}
data={[
{
name: 'value',
description: 'The value you want to bounce.',
required: 'Yes',
type: 'any'
},
{
name: 'delay',
description: 'The delay time in milliseconds.',
required: 'No',
type: 'number'
}
]}
/>

### Returns

<ApiTable
head={{
name: 'Returns'
}}
data={[
{
name: 'debouncedValue',
type: 'any',
description: 'The debounce value. After the delay time has elapsed without the value changing, it will be updated to the most recent value.',
}
]}
/>
72 changes: 72 additions & 0 deletions docs/es/use-debounce.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: useDebounce
description: Devuelve un valor sin rebotes del valor proporcionado.
---

## Instalación

Instala el custom hook desde su linea de comando.

<Snippet pkg text='@raddix/use-debounce' />

## Uso

```tsx
import { useState } from 'react';
import { useDebounce } from 'ahooks';

export default function App() {
const [value, setValue] = useState<string>();
const debouncedValue = useDebounce(value, { wait: 500 });

return (
<div>
<input
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Typed value"
/>
<p>DebouncedValue: {debouncedValue}</p>
</div>
);
};
```

## API

### Parámetros

<ApiTable
head={{
name: 'Parámetros'
}}
data={[
{
name: 'value',
description: 'El valor que desea rebotar.',
required: 'Si',
type: 'any'
},
{
name: 'delay',
description: 'El tiempo de retardo en milisegundos.',
required: 'No',
type: 'number'
}
]}
/>

### Devuelve

<ApiTable
head={{
name: 'Devuelve'
}}
data={[
{
name: 'debouncedValue',
type: 'any',
description: 'El valor sin rebote. Una vez transcurrido el tiempo de retardo sin que el valor cambie, este se actualizará al valor más reciente.',
}
]}
/>

0 comments on commit abfd2c2

Please sign in to comment.