Skip to main content

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

ParameterTypeDefault valueDescription
entityProviderEntitiesProviderundefinedThe entity provider.
watchedComponentskeyof ComponentsRecord[] | "any"[]-

Returns

{
isPending: boolean;
entities: Entity[];
}

The entities and a flag indicating if the entities are pending loading.

NameType
isPendingboolean
entitiesEntity[]

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>;