2024-02-04 17:08:39 +08:00
|
|
|
import type React from 'react';
|
2023-03-21 13:00:34 +08:00
|
|
|
import { useLayoutEffect, useState } from 'react';
|
2023-02-01 11:16:22 +08:00
|
|
|
|
2024-02-04 17:08:39 +08:00
|
|
|
const ClientOnly: React.FC<React.PropsWithChildren> = ({ children }) => {
|
2023-02-01 11:16:22 +08:00
|
|
|
const [clientReady, setClientReady] = useState<boolean>(false);
|
|
|
|
|
2023-03-21 13:00:34 +08:00
|
|
|
useLayoutEffect(() => {
|
2023-02-01 11:16:22 +08:00
|
|
|
setClientReady(true);
|
|
|
|
}, []);
|
|
|
|
|
2024-02-04 17:08:39 +08:00
|
|
|
return clientReady ? (children as React.ReactElement) : null;
|
2023-02-01 11:16:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ClientOnly;
|