UNPKG

@playcanvas/react

Version:

A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.

23 lines 736 B
import { useEffect, useCallback } from "react"; import { useApp } from "./use-app"; /** * useFrame hook — registers a callback on every frame update. * The callback receives the delta time (dt) since the last frame. */ export const useFrame = (callback) => { const app = useApp(); // memoize handler so we can clean up properly const handler = useCallback((dt) => { callback(dt); }, [callback]); useEffect(() => { if (!app) { throw new Error("`useApp` must be used within an Application component"); } app.on("update", handler); return () => { app.off("update", handler); }; }, [app, handler]); }; //# sourceMappingURL=use-frame.js.map