react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

[UseAsyncList] Support automatic client-side sorting after initial load

Open GrantRussell opened this issue 3 years ago โ€ข 3 comments

๐Ÿ™‹ Feature Request

On initial load, it would be nice if the sort option in useAsyncList was automatically called if the initialSortDescriptor option is also provided.

Alternatively, if this is not possible, it would be nice to update the doc page for useAsyncList to explicitly show that the user is responsible for managing the sort. The current documentation gives the impression that client-side sorting will be applied after implementing the provided code example, when in reality the final step is to manually call the sort option.

๐Ÿค” Expected Behavior

When passing a sort and initialSortDescriptor option, useAsyncList would automatically call the passed sort option upon resolving the initial async load.

๐Ÿ˜ฏ Current Behavior

Currently, the user is responsible for managing when the first client-side sort is applied, even though the expectation would be to apply the sort automatically especially if an initialSortDescriptor is also provided.

๐Ÿ’ Possible Solution

See Expected Behavior

๐Ÿ”ฆ Context

After reading examples in the documentation of useAsyncList, it gives the impression that client-side sorting will be applied after supplying the sort option to useAsyncList. This doesn't seem to be the case, but the docs also don't offer any suggestions on how to apply that first sort.

๐Ÿ’ป Examples

https://codesandbox.io/s/listview-with-useasynclist-4cozi2?file=/src/App.js

๐Ÿงข Your Company/Team

Adobe Assets Essentials

๐ŸŽ Tracking Ticket (optional)

GrantRussell avatar Jan 25 '23 19:01 GrantRussell

Discussed with the team further. We'll want to update the docs here to be clear about how to perform sorting here since we don't know what exactly the user provided sort function will do (it might be server side and we'd want to avoid firing another network request).

LFDanLu avatar Jan 25 '23 21:01 LFDanLu

Hi there ! Bumping this issue as this was effectively not straightforward behavior...

Spriithy avatar Dec 26 '23 14:12 Spriithy

This caught me off guard as well. I'd love some recommendations on how to have the list use my sort function on load on the client only.

steveoh avatar Jun 25 '24 17:06 steveoh