ant-design/.dumi/theme/common/ClientOnly.tsx
MadCcc 79c25f620a
chore: codepen input render on client (#40478)
* fix: codepen input render on client

* chore: client only

* chore: code clean
2023-02-01 11:16:22 +08:00

19 lines
436 B
TypeScript

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