mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Update project dependencies to React 19 and Next.js 15, including TypeScript type adjustments and async parameter handling across multiple components
29 lines
909 B
TypeScript
29 lines
909 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
|
|
}) {
|
|
// Only create stylesheet once with lazy initial state
|
|
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
|
|
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 as React.ReactElement<any> | number | string}
|
|
</StyleSheetManager>
|
|
);
|
|
}
|