khteh
khteh

Reputation: 3976

React.JS dynamic import of non-default property/symbol

import BraftEditor, { ControlType } from 'braft-editor'

For the default property BraftEditor:

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

How about that for the non-default property/symbol of 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/[email protected] 
npm ERR!   at location: /project/packages/lib 

Upvotes: 0

Views: 935

Answers (1)

Cup hat blue
Cup hat blue

Reputation: 11

you can import the component like this

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

or you can import default

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

Upvotes: 1

Related Questions