代码之家  ›  专栏  ›  技术社区  ›  khteh

React.JS动态导入非默认属性/符号

  •  0
  • khteh  · 技术社区  · 3 年前
    import BraftEditor, { ControlType } from 'braft-editor'
    

    对于默认属性 BraftEditor :

    const BraftEditorNoSSR = dynamic(import('braft-editor'), {ssr: false})
    

    的非默认属性/符号如何 ControlType ?

    ./DraftEditor.tsx:11:42
    Type error: Property 'ControlType' does not exist on type 'typeof import("/project/node_modules/braft-editor/index")'.
    
       9 | const BraftEditor = dynamic(import('braft-editor'), {ssr: false})
      10 | const ControlType = dynamic(() =>
    > 11 |   import('braft-editor').then(lib => lib.ControlType), {ssr: false}
         |                                          ^
      12 | );
      13 | const CLASS_NAME = 'MuiEditor-root'
      14 | const useStyles = makeStyles((theme: Theme) => ({
    npm ERR! Lifecycle script `build` failed with error: 
    npm ERR! Error: command failed 
    npm ERR!   in workspace: @app/lib@0.0.1 
    npm ERR!   at location: /project/packages/lib 
    
    0 回复  |  直到 3 年前
        1
  •  0
  •   Cup hat blue    3 年前

    可以像这样导入组件

    const ControlType = dynamic(() =>
      import('braft-editor').then(lib => lib.ControlType),
    );
    

    或者您可以导入默认值

    const Braft = dynamic(() => import('braft-editor'));
    

    希望这能有所帮助!!

    推荐文章