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

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

    创建一个稳定的句柄,它在主线程函数中会解析为所给类型的对象。

    这个原语面向库的 hook。返回的目标类型只能在主线程函数中调用,不能在后台运行时中使用。

    Type Parameters

    Type Parameter
    I
    O extends object

    Parameters

    ParameterTypeDescription
    objectTypeMainThreadObjectType<I, O>用于创建目标对象的定义。
    initialValueI可 JSON 序列化的初始化数据。

    Returns

    O

    只在主线程可用的目标类型。

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。