【发布时间】:2019-08-14 17:13:18
【问题描述】:
我正在编写一个包含多个页面的网站。一个页面ComponentA,有一个子组件,它返回带有标题和段落的部分。
ComponentA 中的数组将数据作为道具传递给孩子。在孩子内部,地图函数返回正确的段落。标题缺少什么,如何将title1 传递给paragraph1、title2 传递给paragraph2 等等?
组件A:
import Child from "../components/child";
const ComponentA = () => {
<Layout>
<h1>Home Page</h1>
<Child title={info.title} text={info.text} />
</Layout>
}
const info = {
title: ["Title1", "Title2"],
text: ["Paragraph1", "Paragraph2"]
};
子组件:
const Child = ({ text, title }) => {
return (
<div>
{text.map(text => {
return (
<div>
<h3>{title}</h3>
<p>{text}</p>
</div>
);
})}
</div>
);
};
【问题讨论】:
标签: javascript arrays reactjs