数据可以通过道具传递到组件。
https://facebook.github.io/react/tutorial/tutorial.html#passing-data-through-
props
在您的情况下,道具可以通过在组件内部访问
this.props。
<TodoList />需要一个称为项的道具,它是一个数组。在内部,
<TodoList />您可以映射该数组并返回元素。
例如,在您的类的render方法中,您将返回带有道具的TodoList:
const myItems = [{ name: 'item 1' }, { name: 'item2' }];function MyApp() { return ( <TodoList items={myItems} /> );}然后在TodoList中映射项目
function TodoList({ items }) { return items.map(item => ( <h1>{item.name}</h1> ));}


