Function: useEntity()
function useEntity(
entityProvider: EntityProvider,
watchedComponents: keyof ComponentsRecord[] | "any",
): {
isPending: boolean;
entity: Entity | null;
};
Defined in: livelink.react/sources/hooks/useEntity.ts:98
A hook that provides an entity and a flag indicating if the entity is pending loading.
When the component is unmounted and if the entity was created using this hook,
the entity is deleted from the scene unless delete_on_unmount is set to false.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
entityProvider | EntityProvider | undefined | The entity provider. |
watchedComponents | keyof ComponentsRecord[] | "any" | [] | - |
Returns
{
isPending: boolean;
entity: Entity | null;
}
The entity and a flag indicating if the entity is pending loading.
| Name | Type |
|---|---|
isPending | boolean |
entity | Entity | null |
Example
const { isPending, entity } = useEntity({ euid: "00000000-0000-0000-0000-000000000000" });
if (isPending) {
return <div>Loading...</div>;
}
if (!entity) {
return <div>Entity not found</div>;
}
return <div>Entity found: {entity.name}</div>;