mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
28 lines
843 B
TypeScript
28 lines
843 B
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import { useServerInsertedHTML } from "next/navigation";
|
|
import { StyleProvider, createCache, extractStyle } from "@ant-design/cssinjs";
|
|
import type Entity from "@ant-design/cssinjs/es/Cache";
|
|
|
|
const StyledComponentsRegistry = ({ children }: React.PropsWithChildren) => {
|
|
const cache = React.useMemo<Entity>(() => createCache(), []);
|
|
const isServerInserted = React.useRef<boolean>(false);
|
|
useServerInsertedHTML(() => {
|
|
// avoid duplicate css insert
|
|
if (isServerInserted.current) {
|
|
return;
|
|
}
|
|
isServerInserted.current = true;
|
|
return (
|
|
<style
|
|
id="antd"
|
|
dangerouslySetInnerHTML={{ __html: extractStyle(cache, true) }}
|
|
/>
|
|
);
|
|
});
|
|
return <StyleProvider cache={cache}>{children}</StyleProvider>;
|
|
};
|
|
|
|
export default StyledComponentsRegistry;
|