useChildInstances
TheuseChildInstances
hook provides access to an array of all direct child component instances of a Weaverse component. This allows parent components to interact with, manipulate, or read data from their children.
Import
Type
Parameters
id?: string
- (Optional) The ID of the component whose children to retrieve. If not provided, uses the current component’s ID.
Returns
WeaverseItemStore[]
- An array of child component instances, or an empty array if no children exist
Common Use Patterns
Coordinating Layout and Styles
Parent components can coordinate layout and styling across all children:Managing Interactive Elements
Parent components can manage interactive functionality across children, such as in carousel or tab implementations:Summarizing Child Data
Parent components can collect and summarize data from child components:Implementation Details
TheuseChildInstances
hook:
- Calls
useItemInstance
to get the current component instance (or the instance with the provided ID) - Accesses the children data from the component instance
- Maps through the children IDs to retrieve each child instance from the Weaverse registry
- Returns an array of child component instances
When To Use
- When parent components need to coordinate the behavior or appearance of their children
- When implementing interactive components like carousels, tabs, or accordions
- When collecting or summarizing data from multiple child components
- When applying consistent styling or layout rules across child components
Related
- useItemInstance - Access a specific component instance
- useParentInstance - Access the parent component instance
- useWeaverse - Access the Weaverse instance