From a42237d0f49f9f07c98ef92f925cd45c6d07d5cd Mon Sep 17 00:00:00 2001 From: Soheil Moonesi Date: Sat, 15 Jul 2023 13:49:08 +0430 Subject: [PATCH] toSorted + delete unused props --- src/All_Models.jsx | 13 ++++------- src/App.jsx | 6 ++--- test.js | 56 +++++++++++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/All_Models.jsx b/src/All_Models.jsx index 04a2440..6dbf6da 100644 --- a/src/All_Models.jsx +++ b/src/All_Models.jsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { _data } from "./App"; let listing_models = 1; -export function All_Models({ items, handleAddItems }) { +export function All_Models({ handleAddItems }) { const [sortBy, setSortBy] = useState("product_list"); let sortedItems; @@ -10,18 +10,14 @@ export function All_Models({ items, handleAddItems }) { if (sortBy === "product_list") sortedItems = _data; if (sortBy === "price_list") - sortedItems = _data.slice().sort((a, b) => a.price - b.price); + sortedItems = _data.toSorted((a, b) => a.price - b.price); return ( <>

تمامی محصولات

- setSortBy(e.target.value)}> @@ -38,7 +34,6 @@ export function All_Models({ items, handleAddItems }) { {sortedItems.map((models) => ( @@ -52,7 +47,7 @@ export function All_Models({ items, handleAddItems }) { ); } -function Models({ modelsObj, items, handleAddItems }) { +function Models({ modelsObj, handleAddItems }) { const [buyCount, setBuyCount] = useState(0); function buyCountIncrease() { diff --git a/src/App.jsx b/src/App.jsx index aad7913..f32f6a1 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -12,7 +12,7 @@ export const _data = [ name: "فتوسل 16 آمپر شیوا امواج", price: "239000", photo: "Models/فتوسل 16 آمپر شیوا امواج.jpg", - remaining: "1", + remaining: "10", discountRate: "10", finalPrice: 215000, }, @@ -37,7 +37,7 @@ export const _data = [ name: "فتوسل 16 آمپر شیوا امواج", price: "239000", photo: "Models/فتوسل 16 آمپر شیوا امواج.jpg", - remaining: "1", + remaining: "10", discountRate: "10", finalPrice: 215000, }, @@ -68,7 +68,7 @@ function App() { return (
- +