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

useBehaviour

useBehaviour<T>(behaviour, value): void

The one hook a behaviour is built from: adds the trait to the nearest Entity on mount, sets it when the value changes, removes it on unmount. It compares the value field by field with the one it last wrote, so a render with the same props writes nothing and keeps what a system wrote since. When a field changes, it writes the fields the value names and keeps the trait’s other fields. An entity a system destroyed first is left alone. The behaviour is a leaf of its entity in the devtools tree, under the calling component’s name with the value as its props.

Type Parameter
T extends Trait
Parameter Type
behaviour Behaviour<T>
value BehaviourValue<T>

void