File tree 2 files changed +7
-4
lines changed
website/src/pages/example
2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ export function babelTransform(input: string, filename: string) {
8
8
}
9
9
10
10
export const getTransformValue = ( str : string , filename : string , funName : string ) => {
11
- const isReact = / i m p o r t R e a c t . + f r o m ( " | ' ) r e a c t ( " | ' ) / . test ( str ) ;
11
+ const isReact = / i m p o r t \x20 + R e a c t ( \x20 + | [ \x20 + , ] + ( { [ a - z A - Z 0 - 9 , \s ] + } | { } ) \x20 + ) f r o m \x20 + ( ' | " ) r e a c t ( ' | " ) / . test ( str ) ;
12
12
// 先判断 是否引入 react
13
13
const tran = isReact ? str : `import React from "react"\n ${ str } ` ;
14
14
/** 先把默认导出 export default 进行替换 **/
15
- const newCode = `${ tran . replace ( ' export default' , 'const _default = ' ) } \n` ;
15
+ const newCode = `${ tran . replace ( / e x p o r t \x20 + d e f a u l t / , 'const _default = ' ) } \n` ;
16
16
const code = `${ babelTransform ( newCode , `${ filename } ` ) . code } \n return _react["default"].createElement(_default)` ;
17
17
18
18
return `function ${ funName } (){
Original file line number Diff line number Diff line change @@ -11,11 +11,14 @@ import { Alert } from "uiw";
11
11
// or
12
12
import Alert from " @uiw/react-alert" ;
13
13
```
14
-
14
+ ` import React from 'react' `
15
15
## Basic Usage
16
16
17
17
``` jsx mdx:preview
18
- import React from " react" ;
18
+ import React,{
19
+ useState ,
20
+ useEffect ,
21
+ } from " react" ;
19
22
import ReactDOM from " react-dom" ;
20
23
import { Alert , ButtonGroup , Button } from " uiw" ;
21
24
You can’t perform that action at this time.
0 commit comments