我需要将功能组件(TableSearch.js 和 TableData.js )制作成类组件,第一个类组件应该称为TableSearch和第二个TableData。我刚开始研究 React 和 Redux,所以对我来说仍然很难,而且复杂性在于,在这些函数中,对象是通过参数传递的(解构)。
表搜索.js:
import React from "react";
export default ({ value, onChange, onSearch }) => {
return (
<div className="tableSearch">
<input type="text" className="searchInput" onChange={onChange} value={value} placeholder="Search by flight"/>
<button className="buttonSearch" onClick={() => onSearch(value)}>Search</button>
</div>
);
};
表数据.js:
import React from "react";
export default ({ data }) => (
<div className="tableContainer">
<table className="table">
<thead>
<tr>
<th>Terminal</th>
<th>Gate</th>
<th>Time</th>
<th>Destination</th>
<th>Airline</th>
<th>Flight</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{data.map(item => {
const dt = new Date(item.actual);
const mins = dt.getMinutes();
return (
<tr key={item.ID}>
<td>{item.term}</td>
<td>{item.gateNo}</td>
<td>{`${dt.getHours()}:${mins < 10 ? '0' : ''}${mins}`}</td>
<td>
{item["airportToID.city_en"]
? item["airportToID.city_en"]
: item["airportFromID.city_en"]}
</td>
<td>{item.airline.en.name}</td>
<td>{item["planeTypeID.code"]}</td>
<td>{item.status}</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
如何将这两个功能组件(TableData.js 和 TableSearch.js)更改为类组件?
慕神8447489
相关分类