Implement a simplified React hooks runtime from scratch in plain TypeScript (no React imports). Your runtime must support useState (with batched updates), useEffect (with cleanup and dependency comparison), and useRef. Render a toy 'component' function through two simulated render cycles and assert that state persists, effects fire at the right time, and cleanup runs before re-runs.
Implement the hook queue as a plain array with a module-level cursor that resets to 0 at the start of each render call. useState stores [value, setter] at queue[cursor++]. useEffect stores [cleanup, deps] and runs cleanup then the effect when deps change.
[render 1] hook cursor: 0 → 1 → 2
[effect 1] subscribed (id=42)
--- state update: setCount(1) ---
[cleanup 1] unsubscribed (id=42)
[render 2] hook cursor: 0 → 1 → 2
[effect 2] subscribed (id=42)
Add useCallback and useMemo. Implement batching: collect multiple setX calls within one synchronous block and only re-render once after all have been applied.