I am new to React. I just learned to create an api with nodejs and express from a MySQL. You can check out the json output api at app.subarnanto.com/api/inventory.
How do you render the image? This is my code. I also got a warning
Warning: Each child in an array or iterator should have a unique "key" prop
And the third one, how do I improve my code? Thanks
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>
);
})
}
}