Files
js/components/ClientOnly/ClientOnly.tsx
T
Manan Tank 1e9df14256 ConnectWallet playground improvements (#1590)
* ConnectWallet playground improvements

* add switchToActiveChain

* UI updates

* disable pointerEvents in UI tab for CW
2023-08-25 23:01:38 +00:00

44 lines
909 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;
style?: React.CSSProperties;
}
export const ClientOnly: ComponentWithChildren<ClientOnlyProps> = ({
children,
fadeInDuration,
ssr,
style,
}) => {
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,
...style,
}}
>
{children}
</div>
);
};