Files
js/components/ClientOnly/ClientOnly.tsx
T
Nacho Iacovino 3df9fa935e General fixes and improvements (#1065)
* UI improvements

* Fix tooltip transparency

* Small improvements

* Small stuff

* Add clarification of max num of addresses on airdrop

* Limit changelog section to 2 lines
2023-04-04 08:09:07 +00:00

41 lines
851 B
TypeScript

/* eslint-disable react/forbid-dom-props */
import styles from "./ClientOnly.module.css";
import { ReactNode, useEffect, useState } from "react";
import { ComponentWithChildren } from "types/component-with-children";
interface ClientOnlyProps {
/**
* Use this to server render a skeleton or loading state
*/
ssr: ReactNode;
fadeInDuration?: number;
}
export const ClientOnly: ComponentWithChildren<ClientOnlyProps> = ({
children,
fadeInDuration,
ssr,
}) => {
const [hasMounted, setHasMounted] = useState(false);
useEffect(() => {
setHasMounted(true);
}, []);
if (!hasMounted) {
return <> {ssr} </>;
}
return (
<div
className={styles.fadeIn}
style={{
animationDuration: `${fadeInDuration}ms`,
opacity: fadeInDuration ? 0 : 1,
}}
>
{children}
</div>
);
};