Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

useEvent

useEvent<Record, Delivery, Scope>(event, heard, options?): void

Calls heard once with each event of event, in the order emitted, while the view is mounted: a sound, a flash, a number over a head. The frame loop hands each world’s events to its views once a frame, after the frame’s steps and its animation, so a view hears each event once however many steps the frame ran, and the same events in a room as alone, a network delay later. { entity } hears the events on one entity alone. Without it a view hears every entity’s event, even a view mounted under one <Entity>: an effect that belongs to that entity, such as a coin’s sparks, passes { entity: useEntity() }. A view hears each event emitted after it subscribed; unmounting drops the rest. A server-only event never reaches a view, so its handle fails to typecheck here.

Type Parameter
Record
Delivery extends Reliable | Cosmetic | Local
Scope extends EventScope
Parameter Type
event EventHandle<Record, Delivery, Scope>
heard (event) => void
options ReadEventOptions

void