Skip to content

Commit

Permalink
feat: rename useProList to usePagingList
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Sep 4, 2024
1 parent cb51ff3 commit 574d37f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/react-use/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export * from './use-pausable'
export * from './use-performance-observer'
export * from './use-permission'
export * from './use-previous'
export * from './use-pro-list'
export * from './use-paging-list'
export * from './use-query'
export * from './use-raf-fn'
export * from './use-raf-loop'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ category: ProUtilities
features: ['Pausable', 'DepCollect']
---

# useProList
# usePagingList

import { HooksType, Since } from '@/components'

Expand Down Expand Up @@ -43,11 +43,11 @@ const {
list,
setTotal,
loading
} = useProList(fetcher, options)
} = usePagingList(fetcher, options)

// Pass a function that accepts page, pageSize pagination parameters, which needs to return a data list
// Use setTotal inside this function to set the total data amount, so the paginator can display the total correctly
const { form, query, pagination, selection, list, setTotal, loading } = useProList(
const { form, query, pagination, selection, list, setTotal, loading } = usePagingList(
async (params) => {
const { page, pageSize, form } = params
const { list, total } = await fetchPaginationList({ page, pageSize })
Expand Down Expand Up @@ -105,15 +105,15 @@ const {
list,
setTotal,
loading
} = useProList(fetcher, options)
} = usePagingList(fetcher, options)
```

### Data Fetch Function Fetcher \{#fetcher}

An asynchronous function that takes `params` parameter and returns a data list, which requires calling `setTotal` internally to set the total data amount.

```tsx
export interface UseProListFetcherParams<FormState extends object, Data> {
export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* Data from the last request
*/
Expand All @@ -136,15 +136,15 @@ export interface UseProListFetcherParams<FormState extends object, Data> {
setTotal: ReactSetState<number>
}

export type UseProListFetcher<FormState extends object, Data> = (
params: UseProListFetcherParams<FormState, Data>,
export type UsePagingListFetcher<FormState extends object, Data> = (
params: UsePagingListFetcherParams<FormState, Data>,
) => Promise<Data>
```
### Options \{#options}
```tsx
export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends object> {
export interface UsePagingListOptions<Fetcher extends AnyFunc, FormState extends object> {
/**
* Data fetch function
*
Expand Down Expand Up @@ -175,11 +175,11 @@ export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends ob
### Returns \{#returns}

```tsx
export interface UseProListReturns<
export interface UsePagingListReturns<
Item,
FormState extends object,
Data extends Item[],
Fetcher extends UseProListFetcher<FormState, Data>,
Fetcher extends UsePagingListFetcher<FormState, Data>,
> {
/**
* Whether it is loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { UseQueryOptions } from '../use-query'
import type { ReactSetState } from '../use-safe-state'
import type { AnyFunc } from '../utils/basic'

export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends object> {
export interface UsePagingListOptions<Fetcher extends AnyFunc, FormState extends object> {
/**
* options for `useForm`, see `useForm` for more details
*
Expand All @@ -42,7 +42,7 @@ export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends ob
immediateQueryKeys?: (keyof FormState)[]
}

export interface UseProListFetcherParams<FormState extends object, Data> {
export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* previous data
*/
Expand All @@ -65,15 +65,15 @@ export interface UseProListFetcherParams<FormState extends object, Data> {
setTotal: ReactSetState<number>
}

export type UseProListFetcher<FormState extends object, Data> = (
params: UseProListFetcherParams<FormState, Data>,
export type UsePagingListFetcher<FormState extends object, Data> = (
params: UsePagingListFetcherParams<FormState, Data>,
) => Promise<Data>

export interface UseProListReturns<
export interface UsePagingListReturns<
Item,
FormState extends object,
Data extends Item[],
Fetcher extends UseProListFetcher<FormState, Data>,
Fetcher extends UsePagingListFetcher<FormState, Data>,
> {
/**
* loading status
Expand Down Expand Up @@ -105,12 +105,12 @@ export interface UseProListReturns<
pagination: UsePaginationReturnsState<Data> & UsePaginationReturnsActions
}

export function useProList<
export function usePagingList<
Item,
FormState extends object,
Data extends Item[] = Item[],
Fetcher extends UseProListFetcher<FormState, Data> = UseProListFetcher<FormState, Data>,
>(fetcher: Fetcher, options: UseProListOptions<Fetcher, FormState> = {}) {
Fetcher extends UsePagingListFetcher<FormState, Data> = UsePagingListFetcher<FormState, Data>,
>(fetcher: Fetcher, options: UsePagingListOptions<Fetcher, FormState> = {}) {
const previousDataRef = useRef<Data | undefined>(undefined)
const previousFormRef = useRef<FormState>((options.form?.initialValue || {}) as FormState)
const previousSelectedRef = useRef<Item[]>([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ category: ProUtilities
features: ['Pausable', 'DepCollect']
---

# useProList
# usePagingList

import { HooksType, Since } from '@/components'

Expand Down Expand Up @@ -43,11 +43,11 @@ const {
list,
setTotal,
loading
} = useProList(fetcher, options)
} = usePagingList(fetcher, options)

// 穿入一个接受 page, pageSize 分页参数的函数,它需要返回一个数据列表
// 在这个函数里面使用 setTotal 来设置数据总数,以便分页器能够正确显示总数
const { form, query, pagination, selection, list, setTotal, loading } = useProList(
const { form, query, pagination, selection, list, setTotal, loading } = usePagingList(
async (params) => {
const { page, pageSize, form } = params
const { list, total } = await fetchPaginationList({ page, pageSize })
Expand Down Expand Up @@ -105,15 +105,15 @@ const {
list,
setTotal,
loading
} = useProList(fetcher, options)
} = usePagingList(fetcher, options)
```

### 数据获取函数 Fetcher \{#fetcher}

一个接受 `params` 参数的异步函数,返回一个数据列表,需要在内部调用 `setTotal` 来设置数据总数。

```tsx
export interface UseProListFetcherParams<FormState extends object, Data> {
export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* 上次请求的数据
*/
Expand All @@ -136,15 +136,15 @@ export interface UseProListFetcherParams<FormState extends object, Data> {
setTotal: ReactSetState<number>
}

export type UseProListFetcher<FormState extends object, Data> = (
params: UseProListFetcherParams<FormState, Data>,
export type UsePagingListFetcher<FormState extends object, Data> = (
params: UsePagingListFetcherParams<FormState, Data>,
) => Promise<Data>
```
### 配置项 Options \{#options}
```tsx
export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends object> {
export interface UsePagingListOptions<Fetcher extends AnyFunc, FormState extends object> {
/**
* 数据获取函数
*
Expand Down Expand Up @@ -175,11 +175,11 @@ export interface UseProListOptions<Fetcher extends AnyFunc, FormState extends ob
### 返回值 \{#returns}

```tsx
export interface UseProListReturns<
export interface UsePagingListReturns<
Item,
FormState extends object,
Data extends Item[],
Fetcher extends UseProListFetcher<FormState, Data>,
Fetcher extends UsePagingListFetcher<FormState, Data>,
> {
/**
* 是否正在加载
Expand Down

0 comments on commit 574d37f

Please sign in to comment.