简体   繁体   English

react-styleguidist - 以组件作为道具的示例 - SyntaxError: 不能在模块外使用 import 语句

[英]react-styleguidist - example with Component as a prop - SyntaxError: Cannot use import statement outside a module

I have a component that has props that are components.我有一个具有作为组件的道具的组件。

Component example:

```jsx
import FavoriteBorder from '@material-ui/icons/FavoriteBorder'
import Favorite from '@material-ui/icons/Favorite'

return (
<Component
  favIcon={{
    icon: FavoriteBorder,
    iconSelected: Favorite,
  }}
/>
)
```

Error错误

SyntaxError: Cannot use import statement outside a module

How can I import props我如何导入道具

It turns out the ;事实证明; is the key to this problem.是这个问题的关键。

PropertyCardNew example: PropertyCardNew 示例:

```jsx
import FavoriteBorder from '@material-ui/icons/FavoriteBorder'
import Favorite from '@material-ui/icons/Favorite'
;<PropertyCardNew
  images={
    [
      {
        url: 'https://www.commerciallistings.cbre.co.uk//resources/fileassets/GB-Plus-480572/09e35192/11%20Strand%201_Photo_1_small.jpg',
        alt: "An Image"
      },
      {
        url: 'https://www.commerciallistings.cbre.co.uk//resources/fileassets/GB-Plus-480572/09e35192/11%20Strand%201_Photo_1_small.jpg',
        alt: "An Image"
      }
    ]
  }
  title="PricewaterhouseCoopers"
  favIcon={{
    icon: FavoriteBorder,
    iconSelected: Favorite,
  }}
  subTitle="4th floor"
  street="313 Stoughton Rd Edgerton, WI 53534-1132"
  date="September"
  desks="20+"
  rent="$5600"
  labels={{
    date: 'date',
    desks: 'desks',
    rent: 'Monthly rent',
    link: 'Details',
  }}
  link="https://commerciallistings.cbre.co.uk"
/>

```

I hope this helps somebody.我希望这对某人有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入 React = &#39;SyntaxError: 不能在模块外使用导入语句&#39; - Importing React = 'SyntaxError: Cannot use import statement outside a module' React 16: SyntaxError: 不能在模块外使用 import 语句 - React 16: SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在 React 模块外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module for React SyntaxError: 不能在模块外使用 import 语句 - SyntaxError: Cannot use import statement outside a module SyntaxError: 无法在模块外使用 import 语句 - SyntaxError: Cannot use import statement outside of module 将@SVGR/cli 与模板示例一起使用会引发`SyntaxError: Cannot use import statement outside a module` - Using @SVGR/cli with a template example is throwing `SyntaxError: Cannot use import statement outside a module` 类型:模块导致:语法错误:无法在模块外使用导入语句 - type: module is causing: SyntaxError: Cannot use import statement outside a module JS 导入导出语法错误:不能在模块外使用导入语句 - JS import export SyntaxError: Cannot use import statement outside a module Javascript 模块错误语法错误:不能在模块外使用导入语句 - Javascript Module error SyntaxError: Cannot use import statement outside a module 未捕获的语法错误:无法在模块 Vue.js 单个组件文件之外使用导入语句 - Uncaught SyntaxError: Cannot use import statement outside a module Vue.js single component file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM