在props中得到的问题是 "无法读取未定义的属性'map'" [重复] 。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在props中得到的问题是 "无法读取未定义的属性'map'" [重复] 。相关的知识,希望对你有一定的参考价值。
我有得到的问题,当传递包含对象的数组作为道具从一个组件到另一个组件。你们能不能帮我解决这个问题。
下面是卡信息组件的代码,我在这里把值作为道具传递给你。
const CardsInformation = () =>
const Baba = [
id: 'b1',
header: 'Book 1 Name',
image: 'https://www.google.com/search?q=engineering+books&rlz=1C1CHBF_enIN862IN862&sxsrf=ALeKk01jlMEcOr-2Vd0ev6RaoZZSAqMADg:1589729471894&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjO9dfjm7vpAhV8yjgGHR-zDCoQ_AUoAXoECBMQAw&biw=1536&bih=763#imgrc=OzVmsuZIvusEJM',
discription: 'This book steps beyond the simple functions of the Clapper, introducing you to a number of products that can be used for everything from controlling lighting levels, watering your lawn, closing your drapes, and managing sundry appliances in your home.',
];
return (
<div>
<Card_tabs book=Baba/>
</div>
)
这里是另一个组件,我在使用道具时,在props.book.map处出现了 "无法读取未定义的属性'map'"的问题。
const Card_tabs = (props) =>
props.book.map(user=>
return(<h1>user.header</h1>)
)
答案
import ReactDOM from "react-dom";
import React from "react";
const App = () =>
const Baba = [
id: "b1",
header: "Book 1 Name",
image:
"https://www.google.com/search?q=engineering+books&rlz=1C1CHBF_enIN862IN862&sxsrf=ALeKk01jlMEcOr-2Vd0ev6RaoZZSAqMADg:1589729471894&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjO9dfjm7vpAhV8yjgGHR-zDCoQ_AUoAXoECBMQAw&biw=1536&bih=763#imgrc=OzVmsuZIvusEJM",
discription:
"This book steps beyond the simple functions of the Clapper, introducing you to a number of products that can be used for everything from controlling lighting levels, watering your lawn, closing your drapes, and managing sundry appliances in your home."
];
return (
<div>
<CardTabs book=Baba />
</div>
);
;
const CardTabs = ( book ) =>
return book.map(user =>
return <h1>user.header</h1>;
);
;
ReactDOM.render(<App />, document.getElementById("root"));
以上是关于在props中得到的问题是 "无法读取未定义的属性'map'" [重复] 。的主要内容,如果未能解决你的问题,请参考以下文章
未捕获的类型错误:无法读取切换功能中未定义的属性“prop”
当我尝试在组件中使用antd的表单时,无法读取未定义的属性'getFieldDecorator'
当使用书架的withRelated得到“无法读取未定义的属性'toString'”