useData

tcmts.react.useData · #tpk5ncn6 · term · runs in the browser

uses tcmts.react.router, which uses tcmts.react.createRouter, which uses IntersectionObserver

Read something once per key while the page is open: key names what read reads. What's read already is shown at once; keep shows the previous key's while the next is read. An undefined key reads nothing.

import { router } from "#codebase/tcmts/react";
import type { Data } from "#codebase/tcmts/react";

export const useData = <T>(
  key: string | undefined,
  read: () => Promise<T>,
  options?: { keep?: boolean },
): Data<T> => router.useData(key, read, options) as Data<T>

uses