For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/react/Functions/useMainThreadObject.md.
  • English
    • 简体中文
  • Function: useMainThreadObject()

    useMainThreadObject<I, O extends object>(objectType: MainThreadObjectType<I, O>, initialValue: I): O

    Create a stable handle that resolves to an object of the supplied type in main-thread functions.

    This primitive is intended for library hooks. The returned target type is only callable in a main-thread function; it must not be used from the background runtime.

    Type Parameters

    Type Parameter
    I
    O extends object

    Parameters

    ParameterTypeDescription
    objectTypeMainThreadObjectType<I, O>Definition used to realize the target object.
    initialValueIJSON-serializable initialization payload.

    Returns

    O

    The main-thread-only target type.

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.