reactjs - 我在 react js 中遇到此错误 -- src\components\Allcourse.js Line 20:35: 'course' is not defined no-undef
问题描述
import React, { useState } from 'react';
import Course from './Course';
const Allcourse = () => {
const [courses, setCourse] = useState([
{ title: 'java course', description: 'this is demo' },
{ title: 'react course', description: 'this is demo' },
{ title: 'django course', description: 'this is demo' },
]);
return (
<div>
<h1>All course</h1>
<p>list of courses</p>
{courses.length > 0
? courses.map(item => <Course course={item} />)
: 'No course'}
</div>
);
};
export default Allcourse;
解决方案
我试图复制您的代码以重现错误。从我看到的情况来看,您可能错误地导入了课程组件。仔细检查您的文件路径并确保命名全部正确。
这里有一个可供参考的代码框: https ://codesandbox.io/s/dark-flower-1p160?file=/src/App.js
推荐阅读
- javascript - 我想要 React 中受控组件和不受控组件之间的东西
- flutter - Flutter App 运行没有问题,但是在控制台中出现错误(添加 firebase_messaging backgroundmesssagehandler 后)
- regex - EDI 文件上的正则表达式
- r - R中使用绑定的Oracle查询
- sql - SSRS 2016 报告未显示多页
- python - 使用 Flask-Table 如何更改表格设计?
- android - 在过滤器样式材料组件芯片(Android)中检查图标颜色
- android - 更改 viewModel 数据时,Android Toggle 按钮不会随视图绑定一起更新
- python - 为什么我收到“名称未定义”错误消息?
- unity3d - 布尔值不设置回真