-
Notifications
You must be signed in to change notification settings - Fork 5
/
AntdRegistry.tsx
36 lines (28 loc) · 1 KB
/
AntdRegistry.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use client';
import React, { type FC, useRef, useState } from 'react';
import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs';
import type { StyleProviderProps } from '@ant-design/cssinjs';
import { useServerInsertedHTML } from 'next/navigation';
type AntdRegistryProps = Omit<StyleProviderProps, 'cache'>;
const AntdRegistry: FC<AntdRegistryProps> = (props) => {
const [cache] = useState(() => createCache());
const inserted = useRef(false);
useServerInsertedHTML(() => {
const styleText = extractStyle(cache, { plain: true });
if (inserted.current) {
return null;
}
inserted.current = true;
return (
<style
id="antd-cssinjs"
// to make sure this style is inserted before Ant Design's style generated by client
data-rc-order="prepend"
data-rc-priority="-1000"
dangerouslySetInnerHTML={{ __html: styleText }}
/>
);
});
return <StyleProvider {...props} cache={cache} />;
};
export default AntdRegistry;