Hi @getkey and thanks for answering on eXponenta#7
Your example appears wrong, because you aren't doing anything with the statsAdapter object. I finally got it working with React, sharing my component here:
// eslint-disable-next-line import/no-extraneous-dependencies
import Stats from "stats.js";
import React, { useEffect, useMemo } from "react";
// @ts-ignore
import { PIXIHooks, StatsJSAdapter } from "gstats";
import { useApp, useTick } from "@inlet/react-pixi";
// @ts-ignore gross, but needed by gstat
window.Stats = Stats;
/** @SR
* development env only component to show FPS/RAM/GRAM stats
* *
* FPS: Frames rendered in the last second. The higher the number the better.
* MS: Milliseconds needed to render a frame. The lower the number the better.
* MB: MBytes of allocated memory. (Run Chrome with --enable-precise-memory-info)
* DC: DrawPasses
* TC: Texture count
*/
const DebugStatsView: React.FC = () => {
const app = useApp();
const stats = useMemo(() => new StatsJSAdapter(new PIXIHooks(app)), [app]);
useTick(() => stats?.update());
useEffect(() => {
const domElement = stats.stats.dom || stats.stats.domElement;
domElement.style.top = "";
domElement.style.bottom = "0px";
return stats.stats && document.body.appendChild(domElement);
}, [stats.stats]);
return null;
};
export default DebugStatsView;
Note: couldn't use portals because of a react-pixi error react-pixi: PixiFiber does not support text nodes as children of a Pixi component
Anyways, there seems to be a problem with the npm package, this is the only lib in my ~150 libs project that tsserver cannot find, not sure what this is about.
Using gstats 0.1.0.
I'll keep the ts-ignore
until this is fixed :) Thanks again for making this package!
Edit: while webpack somehow manages to pick of the package and use it locally, my tests are broken with error Cannot find module 'gstats' from 'src/components/DebugStatsView.tsx'
. I'd really like to be able to confirm that gstats is loaded from my tests.