@foxglove/embed-react
Version:
This package provides the `<FoxgloveViewer />` component. It wraps the [`FoxgloveViewer` class](https://docs.foxglove.dev/docs/embed/foxglove-embed) to provide a React API for embedding [Foxglove](https://foxglove.dev/) in your application.
23 lines (20 loc) • 669 B
text/typescript
// This file is copied from @foxglove/viz/hooks/useShouldNotChangeOften.ts
// We copy the file to avoid depending on the viz package.
import { useRef } from "react";
/** Call _warn_ if a given value changes twice within 200 ms */
export function useShouldNotChangeOften<T>(value: T, warn: () => void): T {
const prev = useRef(value);
const prevPrev = useRef(value);
const lastTime = useRef<number>(Date.now());
if (
value !== prev.current &&
prev.current !== prevPrev.current &&
Date.now() - lastTime.current < 200
) {
warn();
}
prevPrev.current = prev.current;
prev.current = value;
lastTime.current = Date.now();
return value;
}