You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

18 lines
448 B

import type { FC, ReactElement, ReactNode } from 'react';
import { useLayoutEffect, useState } from 'react';
export type ClientOnlyProps = {
children: ReactNode;
};
const ClientOnly: FC<ClientOnlyProps> = ({ children }) => {
const [clientReady, setClientReady] = useState<boolean>(false);
useLayoutEffect(() => {
setClientReady(true);
}, []);
return clientReady ? (children as ReactElement) : null;
};
export default ClientOnly;