ecsia-monorepo / react/src / useComponent
Function: useComponent()
ts
function useComponent<C>(handle, def):
| ComponentSnapshot<C>
| undefined;Defined in: react/src/hooks.ts:46
A frozen ComponentSnapshot of def on handle, or undefined when the entity is dead or lacks the component. Re-renders only when an observer event for THIS entity's component lands AND the recomputed snapshot differs field-shallow — a write that lands the same values keeps the previous object identity. Write through the world at the point of use: world.entity(handle).write(C).hp -= 10.
Type Parameters
| Type Parameter |
|---|
C extends ComponentDef<Readonly<Record<string, FieldToken>>, string> |
Parameters
| Parameter | Type |
|---|---|
handle | EntityHandle |
def | C |
Returns
| ComponentSnapshot<C> | undefined