Skip to content

Commit c1fe913

Browse files
committed
feat: no-ssr component
1 parent b7d8705 commit c1fe913

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './no-ssr';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import dynamic from 'next/dynamic';
2+
import type { ReactNode } from 'react';
3+
4+
/**
5+
* Force a component to not be rendered on the server.
6+
*
7+
* In JSX, to differentiate the generic `<P>` from an HTML tag
8+
* then we append a trailing comma as `<P,>`.
9+
*/
10+
const NoSSR = <P,>(
11+
component: React.FC<P> | ReactNode
12+
): React.ComponentType<P> => {
13+
if (typeof component === 'function') {
14+
return dynamic(async () => component, { ssr: false });
15+
}
16+
return NoSSR(() => component);
17+
};
18+
19+
export { NoSSR };

0 commit comments

Comments
 (0)