For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/react.usemainthreadobject.md.
这是开发预览网站。请访问正式文档 lynx-stack.dev

Home > @lynx-js/react > useMainThreadObject

useMainThreadObject() function

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.

Signature:

export declare function useMainThreadObject<I, O extends object>(objectType: MainThreadObjectType<I, O>, initialValue: I): O;

Parameters

Parameter

Type

Description

objectType

MainThreadObjectType<I, O>

Definition used to realize the target object.

initialValue

I

JSON-serializable initialization payload.

Returns:

O

The main-thread-only target type.