这是一个反应初学者练习,所以我正在寻找最简单的解决方案。我需要将这 3 个类组件转换为功能组件。我目前正在学习 React,所以任何有用的评论也将不胜感激。提前致谢!
APP.JS
import React from 'react'
import List from './components/List'
class DataArr extends React.Component {
render() {
const fruits = ["banana", "apple", "pear", "melon", "lemon"]
return (
<div className="DataArr">
<List fruits={fruits}/>
</div>
)
}
}
export default DataArr;
列表.JS
import React from "react";
import Item from "./Item";
class List extends React.Component {
render() {
return (
<div>
{this.props.fruits.map((fruit, index) => {
return <Item key={index} fruit={fruit} />;
})}
</div>
);
}
}
export default List;
项目.JS
import React from 'react'
class Item extends React.Component{
render() {
return (
<div>
{this.props.fruit}
</div>
)
}
}
export default Item;