@runic-artifex/react

Version 0.7.0-preview.5. Read from the published package.

@runic-artifex/react

CollectionViewport re-export
export { CollectionViewport } from '@runic-artifex/views'

Re-exported from CollectionViewport.

CollectionViewportHandle interface
CollectionViewportOptions re-export
export { CollectionViewportOptions } from '@runic-artifex/views'

Re-exported from CollectionViewportOptions.

CommandHandle interface
retrySuspenseView function
function retrySuspenseView(source: ViewConnector<ViewClient>): void;

Forgets a failed useSuspenseView connection, so the next render connects again. Call it from an error boundary's reset before rendering the component again. A connection that is pending or connected is unaffected.

SuspenseViewHandle interface
useCollectionViewport function
function useCollectionViewport(options: CollectionViewportOptions): CollectionViewportHandle;

Follows a fixed-row-height scroll container and returns the rows to request from .NET. Send viewport.start and viewport.size to the ViewModel from an effect; the hook only measures.

useCommand function
function useCommand<TArgs extends readonly unknown[], TReturn>(command: (...args: TArgs) => TReturn): CommandHandle<TArgs, Awaited<TReturn>>;

Tracks a command's pending state and failure for rendering. run always calls the latest command, so it may close over the current client:

const increment = useCommand(() => client?.increment());
<button disabled={!client || increment.pending} onClick={() => increment.run()}>…</button>
useSuspenseView function
function useSuspenseView<TClient extends ViewClient>(source: ViewConnector<TClient> | TClient): SuspenseViewHandle<TClient>;

Suspends the component until a generated View reference connects, then renders its state. A failed connection is thrown to the nearest error boundary; call retrySuspenseView(reference) when resetting the boundary to connect again. An unretried failure is forgotten after ten seconds. Components that pass a reference with the same connect function share one client, which is disposed after the last of them unmounts. Pass a stable function such as a generated page reference or { connect: connectWorkspace }: a function recreated on every render never resolves. An already connected client is observed and left to its owner.

useView function
function useView<TClient extends ViewClient>(source: ViewSource<TClient>): ViewHandle<TClient>;

Connects a generated View reference for the lifetime of the component and renders its state through useSyncExternalStore. A changed reference disposes the previous client; StrictMode's extra mount disposes its connection when it resolves. A reference is identified by its connect function, so an inline { connect: connectWorkspace } does not reconnect. In development a connect function recreated on every render logs a warning.

ViewClient re-export
export { ViewClient } from '@runic-artifex/views'

Re-exported from ViewClient.

ViewConnector re-export
export { ViewConnector } from '@runic-artifex/views'

Re-exported from ViewConnector.

ViewHandle interface
ViewOutlet function
function ViewOutlet<R extends ViewReference>({ content, registry, fallback }: ViewOutletProps<R>): ReactNode;

Renders the registered component for a generated View reference and passes the reference as its page prop. A different reference remounts the component. A kind without a component renders an alert.

ViewOutletProps interface
ViewReference re-export
export { ViewReference } from '@runic-artifex/views'

Re-exported from ViewReference.

ViewRegistry type alias
type ViewRegistry<R extends ViewReference> = {
    readonly [K in R["kind"]]: ComponentType<{
        readonly page: Extract<R, {
            readonly kind: K;
        }>;
    }>;
};

A build-known map checks each generated reference kind against its component's page prop.

ViewSource re-export
export { ViewSource } from '@runic-artifex/views'

Re-exported from ViewSource.