I'm trying to sort my array of objects but its not working. Can someone see why its not working?
function App(){
let products = [
{
name: "LED",
price: 50000,
status: true,
image: "images/products/Krunch-Combo-kfc.png"
},
{
name: "Bike",
price: 40000,
status: false,
image: "images/products/Krunch-Combo-kfc.png"
},
{
name: "Mobile",
price: 60000,
status: true,
image: "images/products/Krunch-Combo-kfc.png"
},
{
name: "Apple Watch",
price: 6000,
status: true,
image: "images/products/Krunch-Combo-kfc.png"
}
];
return (
<div>
<ul>
{
products.sort((a, b) => parseFloat(a.price) - parseFloat(b.price))
}
</ul>
</div>
)
}
export default App;
This is the error I'm getting. Error: Objects are not valid as a React child (found: object with keys {name, price, status, image}). If you meant to render a collection of children, use an array instead.