Skip to main content

useItemInstance

The useItemInstance hook returns a component item store. Pass an instance ID to look up a specific component, or omit it to use the current component from WeaverseItemContext.

Import

Type

Parameters

  • id?: string — The component instance ID. When omitted, the hook uses the current component ID.

Returns

  • WeaverseItemStore | null — The item store, or null when the instance cannot be found.

Common Use Patterns

Accessing the Current Component

Call the hook without an ID inside a rendered Weaverse component:

Accessing a Specific Component

Finding the Closest Weaverse Component

Core Methods and Properties

data

  • Type: ElementData
  • Description: The serialized component data. It always includes id and type, plus component-specific fields.

setData(update)

  • Parameters: Omit<ElementData, 'id' | 'type'>
  • Returns: ElementData
  • Description: Merges the update into the item data and triggers a re-render.

triggerUpdate()

  • Returns: void
  • Description: Forces the component to re-render without changing its data.

_id

  • Type: string
  • Description: The component instance ID.

_element

  • Type: HTMLElement | null
  • Description: The component’s DOM node, when available.

When To Use

  • When a component needs its own runtime data or methods
  • When you need to interact with a component by instance ID
  • When implementing cross-component communication