useParentInstance
TheuseParentInstance
hook allows a component to access its parent component’s instance within the Weaverse component tree. This is useful for implementing child-parent communication patterns and accessing parent component data or methods.
Import
Type
Returns
WeaverseItemStore | null
- The parent component’s instance, ornull
if no parent exists or can’t be found
Common Use Patterns
Accessing Loader Data
The most common pattern is for child components to access loader data that was fetched by their parent component:Getting Product/Collection Data in Feature Sections
Child components commonly use parent data to render products, collections, or other resources:Accessing Configuration Settings
Children can access configuration settings from parent components to adapt their rendering:Fetching External Data
Children can use parent data to determine what external data to fetch:Implementation Details
TheuseParentInstance
hook:
- Uses React’s context API to access the current component’s context, which includes the parent ID.
- Looks up the parent instance in the Weaverse component registry using the parent ID.
- Returns the parent component instance, which includes all its data and methods.
When To Use
- When a child component needs to access data or configuration from its parent.
- When implementing coordinated behavior between parent and child components.
- When you need to access loader data that was fetched at the parent level.
- When a child component’s rendering depends on parent component state or settings.
Related
- useItemInstance - Access a specific component instance
- useChildInstances - Access child component instances
- useWeaverse - Access the Weaverse instance