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

    Function useNextStack

    • Schedules a callback to run in the next microtask (after the current call stack clears).

      This is not a hook — you can call it anywhere inside a component function, including inside useTick, useInitialization, useEffect, etc.

      Most useful when you need to:

      • Access exportsRef.current, child entities, or sibling fibers immediately after mount/refresh
      • Work around cases where the fiber tree isn't fully reconciled yet during the current execution

      Parameters

      • callback: () => void

        Function to run asynchronously in the next microtask

      Returns void

      function Parent() {
      const childrenRef = useRef<KaylaExports<any>[]>([]);

      useInitialization(() => {
      useNextStack(() => {
      // Now children should be mounted & exports available
      const kids = getChildrenEntities(); // or however you collect them
      childrenRef.current = kids.map(k => k.exportsRef?.current).filter(Boolean);
      console.log("Children ready:", childrenRef.current.length);
      });
      });

      return (
      <>
      <Child exportsRef={child1Ref} />
      <Child exportsRef={child2Ref} />
      </>
      );
      }
      useTick(dt => {
      // ... movement logic ...
      useNextStack(() => {
      // check collisions or post-process after all ticks have run
      });
      });