File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1- import { memo } from 'react' ;
1+ import { Root , createRoot } from 'react-dom/client ' ;
22
33import './index.scss' ;
44
5+ let container : HTMLDivElement | null = null ;
6+ let root : Root | null = null ;
7+
58/** Loading组件示例,可替换为ui库的loading组件作二次封装 */
69function Loading ( ) {
710 return (
@@ -30,4 +33,21 @@ function Loading() {
3033 ) ;
3134}
3235
33- export default memo ( Loading ) ;
36+ Loading . show = ( ) => {
37+ if ( container || root ) return ;
38+ container = document . createElement ( 'div' ) ;
39+ container . setAttribute ( 'id' , 'pub-loading' ) ;
40+ root = createRoot ( container ) ;
41+ root . render ( < Loading /> ) ;
42+ document . body . appendChild ( container ) ;
43+ } ;
44+
45+ Loading . hide = ( ) => {
46+ if ( container && root ) {
47+ root . unmount ( ) ;
48+ document . body . removeChild ( container ) ;
49+ container = root = null ;
50+ }
51+ } ;
52+
53+ export default Loading ;
You can’t perform that action at this time.
0 commit comments