Skip to content

Commit

Permalink
docs: enhance docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vikiboss committed Sep 5, 2024
1 parent 1619862 commit 362d711
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
24 changes: 14 additions & 10 deletions packages/react-use/src/use-paging-list/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const {

// 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 } = usePagingList(
const { form, query, pagination, selection, list, refresh, setTotal, loading } = usePagingList(
async (params) => {
const { page, pageSize, form } = params
const { list, total } = await fetchPaginationList({ page, pageSize })
Expand All @@ -68,25 +68,28 @@ const { form, query, pagination, selection, list, setTotal, loading } = usePagin
)

// useForm returns the form object, refer to useForm documentation
// form
form

// useQuery returns the query object, refer to useQuery documentation
// query
query

// usePagination returns the pagination object, merging state and actions, refer to usePagination documentation
// pagination
pagination

// useMultiSelect returns the selection object, merging state and actions, refer to useMultiSelect documentation
// selection
selection

// Data list
// list
list

// Refresh query
refresh

// Set total data amount
// setTotal
setTotal

// Whether it is loading
// loading
loading
```

## Source \{#source}
Expand All @@ -104,6 +107,7 @@ const {
pagination,
selection,
list,
refresh,
setTotal,
loading
} = usePagingList(fetcher, options)
Expand All @@ -118,7 +122,7 @@ export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* Data from the last request
*/
previousData: undefined | Data
previousData: Data | undefined
/**
* Current page number
*/
Expand Down Expand Up @@ -147,7 +151,7 @@ export type UsePagingListFetcher<FormState extends object, Data> = (
```tsx
export interface UsePagingListOptions<Fetcher extends AnyFunc, FormState extends object> {
/**
* Data fetch function
* `useForm` configuration, refer to `useForm` documentation
*
* @defaultValue undefined
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/react-use/src/use-paging-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* previous data
*/
previousData: undefined | Data
previousData: Data | undefined
/**
* current page
*/
Expand Down
26 changes: 15 additions & 11 deletions packages/react-use/src/use-paging-list/index.zh-cn.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const {
loading
} = usePagingList(fetcher, options)

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

// useForm 返回的 form 对象,参考 useForm 文档
// form
form

// useQuery 返回的 query 对象,参考 useQuery 文档
// query
query

// usePagination 返回的 pagination 对象,合并了 state 和 actions,参考 usePagination 文档
// pagination
pagination

// useMultiSelect 返回的 selection 对象,合并了 state 和 actions,参考 useMultiSelect 文档
// selection
selection

// 数据列表
// list
list

// 刷新数据
refresh

// 设置数据总数
// setTotal
setTotal

// 是否正在加载
// loading
loading
```

## 源码 \{#source}
Expand All @@ -104,6 +107,7 @@ const {
pagination,
selection,
list,
refresh,
setTotal,
loading
} = usePagingList(fetcher, options)
Expand All @@ -118,7 +122,7 @@ export interface UsePagingListFetcherParams<FormState extends object, Data> {
/**
* 上次请求的数据
*/
previousData: undefined | Data
previousData: Data | undefined
/**
* 当前页码
*/
Expand Down Expand Up @@ -147,7 +151,7 @@ export type UsePagingListFetcher<FormState extends object, Data> = (
```tsx
export interface UsePagingListOptions<Fetcher extends AnyFunc, FormState extends object> {
/**
* 数据获取函数
* `useForm` 的配置项,参考 useForm 文档
*
* @defaultValue undefined
*/
Expand Down

0 comments on commit 362d711

Please sign in to comment.