mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +08:00
19 lines
448 B
TypeScript
19 lines
448 B
TypeScript
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;
|