@kayelaa/canvas API - v0.2.15
    Preparing search index...

    Variable useRefConst

    useRef: {
        (initialValue: typeof self): KaylaElementRef;
        <T>(initialValue: T): KaylaRef<T>;
    } = ...

    Creates a mutable reference that persists across refreshes and never causes refresh when .current is changed.

    This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks. The call order of all hooks is strictly fixed across every refresh; reordering calls will corrupt internal state.

    Ideal for: mutable game data (position, velocity, timers, audio nodes, DOM refs, previous values), methods, etc. Special usage: pass the self symbol to get a stable reference to the current entity's KaylaRectEntity.

    Type Declaration

    Type of value stored in .current

    Starting value — or self to receive the entity

    Mutable ref object — changes to .current have zero render cost

    const entity = useRef(self);
    entity.current.pos.x += 120 * dt; // direct mutation — no refresh
    const elapsed = useRef(0);
    useTick(dt => { elapsed.current += dt; });