Skip to content

ecsia-monorepo / react/src / useComponentEffect

Function: useComponentEffect()

ts
function useComponentEffect<C>(
   handle, 
   def, 
   callback): void;

Defined in: react/src/hooks.ts:74

Fire callback on every add/remove/change of def on handle WITHOUT re-rendering this component. The callback receives a frozen ComponentSnapshot copy (undefined on remove/despawn), never the pooled EntityRef core observers hand their handlers — a stashed snapshot is harmless where a stashed ref throws. Events arrive at the observer drain inside update(), once per tick per (entity, component).

Type Parameters

Type Parameter
C extends ComponentDef<Readonly<Record<string, FieldToken>>, string>

Parameters

ParameterType
handleEntityHandle
defC
callback(snapshot, ctx) => void

Returns

void

MIT licensed · 0.x, unpublished, experimental.