dashpresshq/dashpress

View on GitHub
src/frontend/components/app/delay-rendering.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import React from "react";

type delayedProps = {
  delayWait: number;
  children: React.ReactNode;
};

export function Delayed({ delayWait = 500, children }: delayedProps) {
  const [delayed, setDelayed] = React.useState(true);

  React.useEffect(() => {
    const timer = setTimeout(() => setDelayed(false), delayWait);
    return () => {
      clearTimeout(timer);
    };
  }, [delayWait]);

  return !delayed && <div>{children}</div>;
}