Function unstable_useAsyncComputedValue

  • Experimental

    React hook to read from an async computed signal. The hook fetches the current value, subscribing to changes via useSyncExternalStore, and triggers a get() call to retrieve updated data. Maintains an internal state for the resolved value of the promise.

    Type Parameters

    • T

      The type of the computed value.

    Parameters

    • alienAsyncComp: AsyncComputed<T>

      The async computed signal to read.

    Returns T | undefined

    The resolved value (or undefined if not yet resolved).

    const asyncSignal = createAsyncComputed<number>(async function*() {
    const val = someSignal.get();
    yield Promise.resolve(someSignal); // track async dep
    return val * 2;
    });

    function AsyncDisplay() {
    const value = useAsyncComputedValue(asyncSignal);
    return <div>Value: {String(value)}</div>;
    }