Function: useEntities()
function useEntities(
entityProvider: EntitiesProvider,
watchedComponents: keyof ComponentsRecord[] | "any",
): {
isPending: boolean;
entities: Entity[];
};
Defined in: livelink.react/sources/hooks/useEntities.ts:69
A hook that provides entities and a flag indicating if the entities are pending loading.
When the component is unmounted and if the entities were created using this hook,
the entities are deleted from the scene unless delete_on_unmount is set to false.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
entityProvider | EntitiesProvider | undefined | The entity provider. |
watchedComponents | keyof ComponentsRecord[] | "any" | [] | - |
Returns
{
isPending: boolean;
entities: Entity[];
}
The entities and a flag indicating if the entities are pending loading.
| Name | Type |
|---|---|
isPending | boolean |
entities | Entity[] |
Example
const { isPending, entities } = useEntities({ components: [{ name: "entity1" }, { name: "entity2" }] });
if (isPending) {
return <div>Loading...</div>;
}
if (!entities.length) {
return <div>Entities not found</div>;
}
return <div>Found {entities.length} entities</div>;