【发布时间】:2020-07-16 18:53:51
【问题描述】:
我收到以下错误,不知道为什么?
我是 REACT 的新手,对基础知识很困惑,我有义务向这个小组寻求帮助。
TypeError: Cannot destructure property 'list2' of 'undefined' as it is undefined.
SimpleList5
C:/Nusrat/react/material-ui/src/Testmap3.jsx:14
11 | <SimpleList5 list2={mylist} />
12 | );
13 |
> 14 | const SimpleList5 = ({ list2 }) => (
| ^ 15 | list2.map(item => (
16 | <li key={item}>{item}</li>
17 | ))
代码是:
import React from 'react'
export const Testmap3 = () => {
//If we would use the List as child component in another
//component, we could pass the list as props to it:
const mylist = ['a', 'b', 'c'];
const App = () => (
<SimpleList5 list2={mylist} />
);
const SimpleList5 = ({ list2 }) => (
list2.map(item => (
<li key={item}>{item}</li>
))
)
return (
<div>
SimpleList5 : {SimpleList5()}
</div>
)
}
export default Testmap3;
【问题讨论】:
标签: javascript reactjs