-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathdynaymicCSS.tsx
More file actions
59 lines (51 loc) · 1.19 KB
/
dynaymicCSS.tsx
File metadata and controls
59 lines (51 loc) · 1.19 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import type { Prepend } from 'rc-util/es/Dom/dynamicCSS';
import { removeCSS, updateCSS } from 'rc-util/es/Dom/dynamicCSS';
import React from 'react';
function injectStyle(id: number, prepend?: Prepend, priority?: number) {
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
updateCSS(`body { background: #${randomColor} }`, `style-${id}`, {
prepend,
priority,
});
}
const Demo = () => {
const [id, setId] = React.useState(0);
const idRef = React.useRef<number>(id);
idRef.current = id;
// Clean up
React.useEffect(() => {
return () => {
for (let i = 0; i <= idRef.current; i += 1) {
removeCSS(`style-${i}`);
}
};
}, []);
return (
<>
<button
onClick={() => {
injectStyle(id, 'queue');
setId(id + 1);
}}
>
Prepend Queue: {id}
</button>
<button
onClick={() => {
injectStyle(id, 'queue', -1);
setId(id + 1);
}}
>
Prepend Queue Priority: {id}
</button>
<button
onClick={() => {
injectStyle(-1);
}}
>
Append
</button>
</>
);
};
export default Demo;