Skip to content

Commit

Permalink
feat(useLoadMore): 导出 setData
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jan 30, 2021
1 parent c13dffd commit 4c7546e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/react/__snapshots__/useLoadMore.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -38,6 +39,7 @@ Object {
"noMore": true,
"pageNumber": 2,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 2,
}
`;
Expand All @@ -61,6 +63,7 @@ Object {
"noMore": true,
"pageNumber": 2,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 2,
}
`;
Expand All @@ -75,6 +78,7 @@ Object {
"noMore": true,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 2,
}
`;
Expand All @@ -94,6 +98,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 2,
}
`;
Expand All @@ -117,6 +122,7 @@ Object {
"noMore": false,
"pageNumber": 3,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand Down Expand Up @@ -144,6 +150,7 @@ Object {
"noMore": false,
"pageNumber": 3,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -163,6 +170,7 @@ Object {
"noMore": false,
"pageNumber": 2,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -186,6 +194,7 @@ Object {
"noMore": false,
"pageNumber": 2,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -200,6 +209,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -219,6 +229,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -233,6 +244,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
Expand All @@ -252,6 +264,7 @@ Object {
"noMore": false,
"pageNumber": 1,
"reload": [Function anonymous],
"setData": [Function bound dispatchAction],
"total": 0,
}
`;
13 changes: 12 additions & 1 deletion src/react/useLoadMore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { DependencyList, useCallback, useEffect, useRef, useState } from 'react'
import {
DependencyList,
Dispatch,
SetStateAction,
useCallback,
useEffect,
useRef,
useState,
} from 'react'
import { useLatest } from 'react-use'

/**
Expand Down Expand Up @@ -66,6 +74,8 @@ export interface UseLoadMoreResult<TItem> {
loadMore: () => Promise<void>
/** 从首页重新加载数据 */
reload: () => Promise<void>
/** 设置数据 */
setData: Dispatch<SetStateAction<TItem[]>>
}

/**
Expand Down Expand Up @@ -165,5 +175,6 @@ export function useLoadMore<TItem>(
noMore,
loadMore,
reload,
setData,
}
}

0 comments on commit 4c7546e

Please sign in to comment.