can you guys help me? I am newbie learning react. I have a reacts page like this. I already make a data and i put them inside usesate(). can you guys help me make array data showing up in html?? I am just learning about useState function.
import React, {useState} from 'react';
import './Soal2.css';
import hamburger from './products/humburger.jpg';
import kimchi from './products/kimchi.jpg';
import topokki from './products/topokki.jpg'
import sushi from './products/sushi.jpg';
function Soal2() {
const [listProducts, setListProducts] = useState([{
menu: 'Humburger',
gambar: {hamburger},
harga: 10000
},
{
menu: 'Kimchi',
image: {kimchi},
harga: 15000
},
{
menu: 'Topokki',
gambar: {topokki},
harga: 20000
},
{
menu: 'Sushi',
gambar: {sushi},
harga: 25000
}])
return (
</div> ---> array data showing up here
</div>
);
}
export default Soal2;
the requirement is const [listProducts, setListProducts] and useState([array of objects]) didnt allowed to erase. Please help me :(
All i did is making new component file name productitem.js like this:
function ProductItem(listProducts) {
return (
<div>
{listProducts}
</div>
);
}
export default ProductItem;
and then I am going to return the code to make array data show in html :
{listProducts.map((item, index) => {
return <ProductItem value={item} key={index}/>
})}
but the code is error. there is something like : objects are not valid as a react child (found: object with keys {value}), bla bla ---> error code