Skip to content

Picker with infinite scroll / useAsyncList #1496

Closed
@mfilteau

Description

@mfilteau

❔ Question

I've been trying to create a listbox-based component with async loading & infinite content using useAsyncList,

As it was not working as expected, I went to the basic and tried the code sample based on the (see below).

However, once the initial entries have been displayed, scrolling at the end of the picker's list doesn't load more items.

Is it supposed to work?

Thanks!

🔦 Context

💻 Code Sample

import './App.css';
import { Provider, defaultTheme, Picker, Item, useAsyncList, View } from '@adobe/react-spectrum';

function App() {
    let list = useAsyncList({
        async load({signal, cursor}) {
            console.log('loading', cursor);
          // If no cursor is available, then we're loading the first page.
          // Otherwise, the cursor is the next URL to load, as returned from the previous page.
          let res = await fetch(cursor || 'https://pokeapi.co/api/v2/pokemon', {
            signal
          });
          let json = await res.json();
          return {
            items: json.results,
            cursor: json.next
          };
        }
      });
      return (
      <Provider theme={defaultTheme}>
        <View borderWidth="thin" borderColor="dark" padding="size-200">
          <Picker label="Select a pokemon" items={list.items} isLoading={list.isLoading} onLoadMore={list.onLoadMore}>
            {(item) => <Item key={item.name}>{item.name}</Item>}
          </Picker>
        </View>
      </Provider>
    );
}

export default App;

🌍 Your Environment

Software Version(s)
react-spectrum 3.7.0
Browser Edge 87.0.664.75
Operating System Windows 10

🧢 Your Company/Team

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions