Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

No error handling available for createInfiniteScroll

Aperta
#795 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
frontend

Direzione di ricerca

Inizia dal punto di ingresso createInfiniteScroll mostrato nell’issue e confronta la relativa documentazione JSX con l’API restituita e l’utilizzo di createResource. Conferma il comportamento previsto degli stati di caricamento e di errore, quindi verifica che l’API pubblica esponga entrambi gli stati e che il comportamento pertinente sia testato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Describe the bug

In the JSX Docs it clearly says that we get any errors using pages.error but the current implementation has not property that says error and loading... How am I suppose to get errors back

/**
 * Provides an easy way to implement infinite scrolling.
 *
 * ```ts
 * const [pages, loader, { page, setPage, setPages, end, setEnd }] = createInfiniteScroll(fetcher);
 * ```
 * @param fetcher `(page: number) => Promise<T[]>`
 * @return `pages()` is an accessor contains array of contents
 * @property `pages.loading` is a boolean indicator for the loading state
 * @property `pages.error` contains any error encountered
 * @return `infiniteScrollLoader` is a directive used to set the loader element
 * @method `page` is an accessor that contains page number
 * @method `setPage` allows to manually change the page number
 * @method `setPages` allows to manually change the contents of the page
 * @method `end` is a boolean indicator for end of the page
 * @method `setEnd` allows to manually change the end
 */
export function createInfiniteScroll<T>(fetcher: (page: number) => Promise<T[]>): [
  pages: Accessor<T[]>,
  loader: (el: Element) => void,
  options: {
    page: Accessor<number>;
    setPage: Setter<number>;
    setPages: Setter<T[]>;
    end: Accessor<boolean>;
    setEnd: Setter<boolean>;
  },
] {
  const [pages, setPages] = createSignal<T[]>([]);
  const [page, setPage] = createSignal(0);
  const [end, setEnd] = createSignal(false);

  let add: (el: Element) => void = noop;
  if (!isServer) {
    const io = new IntersectionObserver(e => {
      if (e.length > 0 && e[0]!.isIntersecting && !end() && !contents.loading) {
        setPage(p => p + 1);
      }
    });
    onCleanup(() => io.disconnect());
    add = (el: Element) => {
      io.observe(el);
      tryOnCleanup(() => io.unobserve(el));
    };
  }```

  const [contents] = createResource(page, fetcher);

  createComputed(() => {
    const content = contents.latest;
    if (!content) return;
    batch(() => {
      if (content.length === 0) setEnd(true);
      setPages(p => [...p, ...content]);
    });
  });

  return [
    pages,
    add,
    {
      page: page,
      setPage: setPage,
      setPages: setPages,
      end: end,
      setEnd: setEnd,
    },
  ];
}

### Minimal Reproduction Link

https://example.com/
Lingua principale
TypeScript
Stelle
1.6k
Fork
162
Merge medio
19h 40m
PR unite (30g)
8

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solidjs-community/solid-primitives

Tutte le issue di solidjs-community/solid-primitives

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.