无法显示数组项目和标志错误:未介绍的TypeError:无法读取未定义的属性(Reading' MAP')
我是一个仍在调情reactjs的新鸟。为什么每当我尝试显示任务的数组内容时,我都会遇到此错误。 这是我的app.js
import React from 'react';
import { useState } from 'react'
import './index.css';
import Navbar from './components/layout/Navbar';
import Tasks from './components/Tasks';
// import Message from './components/Message';
// import FunctionClick from './components/FunctionClick';
const App = () => {
const [tasks, setTasks] = useState([
{
id: 1,
text: 'This is the first text',
day: 'Feb 5th at 2:30pm',
reminder: true,
},
{
id: 2,
text: 'Meeting at School',
day: 'Feb 6th at 1:30pm',
reminder: true,
},
{
id: 3,
text: 'third meeting',
day: 'Feb 6th at 1:30pm',
reminder: true,
},
])
return (
<div className="container">
<Navbar />
<Tasks tasks={tasks}/>
</div>
);
}
export default App;
,这是我的
import React from 'react'
import Task from './Task'
const Tasks = ({tasks}) => {
return (
<>
{tasks.map((task) => (
<Task key={task.id} task={task} />
))}
</>
)
}
export default Tasks
任务
import React from 'react'
export const Task = ({task}) => {
return (
<div className='task'>
<h3>{task.text}
</h3>
</div>
)
}
export default Task;
。我一直被困。请帮我。您可以尝试在应用程序上测试它。谢谢
i'm a newbee still flirting around reactjs. why do i get this error anytime i trying displaying the array content of tasks.
this is my App.js
import React from 'react';
import { useState } from 'react'
import './index.css';
import Navbar from './components/layout/Navbar';
import Tasks from './components/Tasks';
// import Message from './components/Message';
// import FunctionClick from './components/FunctionClick';
const App = () => {
const [tasks, setTasks] = useState([
{
id: 1,
text: 'This is the first text',
day: 'Feb 5th at 2:30pm',
reminder: true,
},
{
id: 2,
text: 'Meeting at School',
day: 'Feb 6th at 1:30pm',
reminder: true,
},
{
id: 3,
text: 'third meeting',
day: 'Feb 6th at 1:30pm',
reminder: true,
},
])
return (
<div className="container">
<Navbar />
<Tasks tasks={tasks}/>
</div>
);
}
export default App;
and this is my Tasks.js
import React from 'react'
import Task from './Task'
const Tasks = ({tasks}) => {
return (
<>
{tasks.map((task) => (
<Task key={task.id} task={task} />
))}
</>
)
}
export default Tasks
Task.js
import React from 'react'
export const Task = ({task}) => {
return (
<div className='task'>
<h3>{task.text}
</h3>
</div>
)
}
export default Task;
it doesn't show error in the console but shows in the browser. i've been stuck. help me please. you can try testing it on your app. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,根据您的错误
,如果您进行更改,
则可以跳过该错误,就像您在
任务中的条件
组件中放置的那样,要检查任务
arrayI think as per your error
if you make changes as following
then you can skip that error, As you can see I put if condition inside
Tasks
component to checktasks
array