ilokesto

Async data guide

Async UI usually has four states: loading, error, empty, and success. Utilinent keeps each state visible without deeply nested ternaries.

import { For, Show } from '@ilokesto/utilinent';

export function Products({ data, loading, error }) {
  return (
    <Show when={!loading} fallback={<ProductsSkeleton />}>
      <Show when={!error} fallback={<ErrorPanel error={error} />}>
        <For.ul each={data?.items} fallback={<EmptyProducts />}>
          {(product) => <ProductRow key={product.id} product={product} />}
        </For.ul>
      </Show>
    </Show>
  );
}
  1. Gate loading first.
  2. Gate error second.
  3. Render the array with For and an empty fallback.
  4. Keep row rendering in a small component.

This order mirrors what users see: first wait, then recover from errors, then handle empty or populated data.

When to use Mount or Slacker

Use Mount when the component itself should resolve a node-producing function. Use Slacker when loading should not begin until the section becomes visible.

Function identity decides when async work restarts

Both Mount and Slacker key their async work off function identity, not off the values a function captures. An inline () => fetchX(id) or inline onError is a new function on every parent render, so unrelated re-renders restart the work. Wrap the real inputs in useCallback dependencies — useCallback(() => fetchX(id), [id]) survives unrelated re-renders, and a changed id is the intended restart. Changing onError identity also restarts Mount's current attempt.

Both components also pass the current attempt's AbortSignal to factories and loaders, so a replaced or unmounted attempt can cancel its underlying request. See the Mount reference and Slacker reference for the full cancellation and identity contracts with verified examples.

On this page