Skip to content

Commit

Permalink
docs: refine docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Nov 29, 2024
1 parent 07658d4 commit e79df57
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/react-use/src/use-retry-fn/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ export interface UseRetryFnOptions<E = unknown> {
}
```

### Returns \{#returns}

A function with retry mechanism, with the same signature as the input function, with an additional `cancel` method.

```tsx
export function useRetryFn<T extends AnyFunc, E = any>(
fn: T,
options: UseRetryFnOptions<E> = {},
): T & { cancel: () => void }
```
2 changes: 1 addition & 1 deletion packages/react-use/src/use-retry-fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface UseRetryFnRetryState {
version: object
}

export function defaultRetryInterval(currentCount: number) {
export function defaultRetryInterval(currentCount: number): number {
const nextInterval = 1000 * 2 ** (currentCount - 1)
return nextInterval >= 30_000 ? 30_000 : nextInterval
}
Expand Down
13 changes: 12 additions & 1 deletion packages/react-use/src/use-retry-fn/index.zh-cn.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Source } from '@/components'

<Source />

## API API \{#api}
## API \{#api}

```tsx
const fnWithRetry = useRetryFn(fn, options)
Expand Down Expand Up @@ -75,3 +75,14 @@ export interface UseRetryFnOptions<E = unknown> {
onRetryFailed?: (error: E | undefined, state: UseRetryFnRetryState) => void
}
```

### 返回值 \{#returns}

一个带有重试机制、与传入函数签名相同的函数,带有额外的 `cancel` 方法。

```tsx
export function useRetryFn<T extends AnyFunc, E = any>(
fn: T,
options: UseRetryFnOptions<E> = {},
): T & { cancel: () => void }
```

0 comments on commit e79df57

Please sign in to comment.