mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-28 09:58:49 +05:00
30 lines
751 B
TypeScript
30 lines
751 B
TypeScript
|
|
'use client';
|
||
|
|
|
||
|
|
import React, { useState } from 'react';
|
||
|
|
import { useServerInsertedHTML } from 'next/navigation';
|
||
|
|
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';
|
||
|
|
|
||
|
|
export default function StyledComponentsRegistry({
|
||
|
|
children,
|
||
|
|
}: {
|
||
|
|
children: React.ReactNode;
|
||
|
|
}) {
|
||
|
|
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
|
||
|
|
|
||
|
|
useServerInsertedHTML(() => {
|
||
|
|
const styles = styledComponentsStyleSheet.getStyleElement();
|
||
|
|
styledComponentsStyleSheet.instance.clearTag();
|
||
|
|
return <>{styles}</>;
|
||
|
|
});
|
||
|
|
|
||
|
|
if (typeof window !== 'undefined') {
|
||
|
|
return <>{children}</>;
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
|
||
|
|
{children}
|
||
|
|
</StyleSheetManager>
|
||
|
|
);
|
||
|
|
}
|