--- title: Pass an Array as Props localeTitle: 将数组作为道具传递 --- ## 将数组作为道具传递 要将数组作为prop传递,首先必须在要呈现的每个组件上将数组声明为“tasks”prop: ```javascript const List= (props) => { return
}; class ToDo extends React.Component { constructor(props) { super(props); } render() { return ({props.tasks.join(", ")}
}; // ... same as above ``` `.join(", ")`方法用于从数组中获取每个元素,并将它们连接到要显示的字符串中。 我们在此示例中使用React的模块化来显示由两个不同组件传递给渲染最终HTML的公共组件的任务。