@gphone/sdk
    Preparing search index...

    Function usePagedList

    • OS Service Hook for a long list revealed a page at a time.

      Extracted from Messages, which had the whole thing written out: a page size, a display limit, a derived window, a hidden-count, an index offset so keyed rows kept their identity, a re-entrancy guard, and the scroll-height arithmetic that stops the view from jumping when older messages appear above the fold. That last part is the reason this is worth sharing — it is the piece everyone forgets, and getting it wrong is invisible until a thread is long enough to scroll.

      olderAt is what makes it serve both shapes. A chat grows upward and must compensate; a feed grows downward and must not. Both window the newest rows first.

      const page = usePagedList({
      items: () => messages,
      olderAt: 'start',
      container: () => document.getElementById('messages-container')
      });

      // {#each page.visible as msg, i (msg.id)} — index i + page.offset is the real one
      // <div onscroll={page.onScroll}>

      A rune module: the window is derived from state the caller owns and must re-derive when either the list or the limit changes.

      Type Parameters

      • T

      Parameters

      Returns {
          loadMore: () => Promise<void>;
          onScroll: (event: Event) => void;
          reset: () => void;
          get hiddenCount(): number;
          get loading(): boolean;
          get offset(): number;
          get visible(): T[];
      }

      • loadMore: () => Promise<void>
      • onScroll: (event: Event) => void
      • reset: () => void

        Back to one page. Call when the list is replaced rather than appended to.

      • get hiddenCount(): number
      • get loading(): boolean
      • get offset(): number
      • get visible(): T[]