【问题标题】:'Review' is not exported from './Review' [duplicate]'评论'不是从'./Review'中导出的[重复]
【发布时间】:2021-03-08 13:30:48
【问题描述】:

我有问题。

我创建了 Review.jsx 文件。 我使用 rafce 并编写了代码。 我想将它导入另一个文件,但它写了一个问题。 “评论”不是从“./Review”导出的

在导入的另一个文件代码中 - import { Review } from './Review';

审阅和这个文件在同一个文件夹中

查看.jsx 代码

import React from 'react';
import { Typography, List, ListItem, ListItemText } from '@material-ui/core';


const Review = ({ checkoutToken }) => {
    return (
        <>
            <Typography variant="h6" gutterBottom>Order Summary</Typography>
            <List disablePadding>
                {checkoutToken.live.line_items.map((product) => (
                    <ListItem style={{padding: '10px 0' }} key={product.name}>
                        <ListItemText primary={product.name} secondary={`Quanity: ${product.quanity}`} />
                        <Typography variant="body2">{product.line_total.formatted_with_symbol}</Typography>

                    </ListItem>
                ))}
                <ListItem style={{padding: '10px 0' }}>
                    <ListItemText primary="Total" />
                    <Typography variant="subtotal" style={{fontWeight: 700}}>
                        {checkoutToken.live.subtotal.formatted_with_symbol}
                    </Typography>

                </ListItem>
            </List>
        </>
    )
}

export default Review;


【问题讨论】:

  • 你能提供一些代码sn-ps吗?也许你的组件和导入行。
  • 请添加评论代码
  • 需要在Review.jsx文件中导出Review函数/类组件。您可以执行默认或命名导出。见Export
  • 这里是评论代码

标签: reactjs jsx


【解决方案1】:

在 Review.jsx 文件中,您需要通过以下方式导出函数/组件:

export const Review = // your function/component here;

只有这样你才能通过以下方式导入它

import { Review } from './Review';

【讨论】:

  • 我使用 rafce,所以它是导出的默认值。请查看编辑后的帖子和代码
  • 你有一个默认导出'export default Review;'在这种情况下,您可以以“import Review from './Review';”格式将评论导入其他文件中
  • 如果你想使用'import { Review } from './Review';'只需删除文件末尾的默认导出并将组件的初始化更改为 'export const Review = ({ checkoutToken }) => { ...'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多