ฉันยังใหม่กับ React ฉันเพิ่งเรียนรู้การสร้าง API ด้วย nodejs และแสดงผลจาก MySQL คุณสามารถตรวจสอบ API เอาต์พุต json ได้ที่ app.subarnanto.com/api/inventory
คุณจะเรนเดอร์ภาพได้อย่างไร? นี่คือรหัสของฉัน ฉันยังได้รับคำเตือน
คำเตือน: เด็กแต่ละคนในอาร์เรย์หรือตัววนซ้ำควรมีเสา "คีย์" ที่ไม่ซ้ำกัน
และอันที่สาม ฉันจะปรับปรุงโค้ดของฉันได้อย่างไร? ขอบคุณ
import React from 'react';
import axios from 'axios';
export default class Inventory extends React.Component {
constructor(props) {
super(props)
this.state = {
inventory: []
}
}
componentDidMount() {
axios.get('https://app.subarnanto.com/api/inventory').then(res => {
this.setState({ inventory: res.data });
console.log({ inventory: res.data });
});
}
render() {
return this.state.inventory.map(itemList => {
let item = itemList;
return (
<div>
<h4>Nama: { item.name } </h4>
<h4>Nomor Seri: { item.serial } </h4>
<h4>ID Tag: { item.tag } </h4>
<img src="{ item.image }"/>
</div>
);
})
}
}