Skip to content

Commit 84ce889

Browse files
LFDanLusnowystingerdannify
authored
Fixing type for load/sort functions in useAsyncList hook (#2683)
* Revert "fix issue #1878, added async to the sort function (#2658)" This reverts commit a984616. * updating type for sort in useAsyncList Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Danni <[email protected]>
1 parent e581ecf commit 84ce889

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

packages/@react-spectrum/table/stories/Table.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ function AsyncLoadingExample() {
10451045
let json = await res.json();
10461046
return {items: json.data.children, cursor: json.data.after};
10471047
},
1048-
async sort({items, sortDescriptor}) {
1048+
sort({items, sortDescriptor}) {
10491049
return {
10501050
items: items.slice().sort((a, b) => {
10511051
let cmp = a.data[sortDescriptor.column] < b.data[sortDescriptor.column] ? -1 : 1;

packages/@react-stately/data/docs/useAsyncList.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ let list = useAsyncList({
135135
async load({signal}) {
136136
// Same load function as before
137137
},
138-
async sort({items, sortDescriptor}) {
138+
sort({items, sortDescriptor}) {
139139
return {
140140
items: items.sort((a, b) => {
141141
// Compare the items by the sorted column

packages/@react-stately/data/src/useAsyncList.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export interface AsyncListOptions<T, C> {
3232
sort?: AsyncListLoadFunction<T, C>
3333
}
3434

35-
type AsyncListLoadFunction<T, C> = (state: AsyncListLoadOptions<T, C>) => Promise<AsyncListStateUpdate<T, C>>;
35+
type AsyncListLoadFunction<T, C> = (state: AsyncListLoadOptions<T, C>) => AsyncListStateUpdate<T, C> | Promise<AsyncListStateUpdate<T, C>>;
36+
3637
interface AsyncListLoadOptions<T, C> {
3738
/** The items currently in the list. */
3839
items: T[],

0 commit comments

Comments
 (0)