This is my Sort.js style component:
<SortWrapper> <SortText>Sort By</SortText> <SortSelect onChange={onSelectChange}> <SortOption value="vehicleMake">Vehicle make</SortOption> <SortOption value="vehicleModel">Vehicle model</SortOption> </SortSelect> </SortWrapper>
This is the function in App.js where the sorting component is rendered
<Sort onSelectChange={onSelectChange} />
This is a function:
const onSelectChange = (e) => { const value = e.target.value; if (value === "VehicleMake") vehicles.sort((a, b) => a.vehicleMake.localeCompare(b.vehicleMake)); else if (value === "VehicleModel") { vehicles.sort((a, b) => a.vehicleModel.localeCompare(b.vehicleModel)); } else { vehicles.sort((a, b) => a.id - b.id); }
"Vehicles" is an array of objects that I get from the Firestore database.
Whenever I change the value of the SortOption, it does not automatically sort the array of objects, but when I click on page 2 in the pagination, and then click on page 1, it sorts it.
This is my grid component:
<Grid> {vehiclesData.map((vehicle) => ( <VehicleCard id={vehicle.id} key={vehicle.id} ImageURL={vehicle.ImageURL} vehicleMake={vehicle.vehicleMake} vehicleModel={vehicle.vehicleModel} selectVehicle={() => setSelectedVehicle(vehicle)} deleteHandler={() => deleteHandler(vehicle.id)} /> ))} </Grid>
This is my filter function:
const vehiclesData = useMemo(() => { let computedVehicles = vehicles; if (searchVehicle) { computedVehicles = computedVehicles.filter((vehicle) => vehicle.vehicleMake.toLowerCase().includes(searchVehicle.toLowerCase()) ); } setTotalVehicles(computedVehicles.length); return computedVehicles.slice( (currentPage - 1) * vehiclesPerPage, (currentPage - 1) * vehiclesPerPage + vehiclesPerPage );
As I wrote before, I want my vehicles to render automatically by make or model, not when I click on the page number in the pagination.
梭子蟹什么季节吃最好 | 口腔医学技术可以考什么证 | 不加一笔是什么字 | 吃皮蛋有什么好处和坏处 | 劲酒加什么好喝 |
易激惹是什么意思 | 子宫切除对女人有什么影响 | 认命是什么意思 | 蝉什么时候叫 | 阳历是什么意思 |
难舍难分是什么意思 | 属羊的跟什么属相犯冲 | 屁多是什么原因 | 舒五行属性是什么 | 84年是什么命 |
什么是权力 | 压寨夫人是什么意思 | 母亲节送给妈妈什么礼物好 | 狗咬到什么程度需要打针 | 胎盘0级是什么意思啊 |
治疗舌苔白厚用什么药hcv8jop4ns6r.cn | 脑梗是什么引起的gangsutong.com | 什么的雄鸡hcv8jop4ns1r.cn | 各自安好是什么意思hcv9jop4ns0r.cn | 是什么品牌hcv8jop8ns6r.cn |
胃胀腹胀吃什么药hanqikai.com | 背水一战是什么意思wmyky.com | 白羊座什么性格hcv9jop2ns4r.cn | nt检查什么内容hcv8jop8ns3r.cn | 胚胎停育是什么原因造成的hcv9jop0ns2r.cn |
猫吃什么hcv8jop8ns9r.cn | vape是什么意思dayuxmw.com | 血崩是什么意思hcv7jop5ns6r.cn | 妈妈像什么hcv9jop4ns9r.cn | 77年属蛇的是什么命hcv7jop9ns9r.cn |
情绪是什么意思helloaicloud.com | 懊恼是什么意思hcv9jop1ns6r.cn | 鱼胶是鱼的什么部位hcv9jop2ns1r.cn | 80岁称什么之年hcv7jop4ns5r.cn | 上行下效是什么意思luyiluode.com |
Your sorting method should be like this
Your filter function should be like this
Basically, once onSelectChange runs, you update the vehicle status and then usememo should run again, so we add the dependent vehicle to it