ant-design/.dumi/theme/common/ClientOnly.tsx

15 lines
383 B
TypeScript
Raw Normal View History

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