get rid of useeffect

This commit is contained in:
Jun-te Kim 2026-01-15 13:59:37 +00:00
parent de947062bb
commit 2bf5cded94

View file

@ -1,6 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import { useState } from "react";
export type PropertyFilterValues = {
address: string;
@ -27,23 +27,27 @@ export default function PropertyFilters({
useState<PropertyFilterValues["expected_epc_at_least"]>("");
/* ----------------------------------------
Auto-fix invalid combinations
Change handlers (no useEffect)
----------------------------------------- */
useEffect(() => {
if (currentEpc && expectedEpc) {
if (epcIndex(expectedEpc) >= epcIndex(currentEpc)) {
setExpectedEpc("");
}
}
}, [currentEpc]);
function handleCurrentEpcChange(
value: PropertyFilterValues["current_epc_at_most"]
) {
setCurrentEpc(value);
useEffect(() => {
if (currentEpc && expectedEpc) {
if (epcIndex(expectedEpc) >= epcIndex(currentEpc)) {
setCurrentEpc("");
}
if (value && expectedEpc && epcIndex(expectedEpc) >= epcIndex(value)) {
setExpectedEpc("");
}
}, [expectedEpc]);
}
function handleExpectedEpcChange(
value: PropertyFilterValues["expected_epc_at_least"]
) {
setExpectedEpc(value);
if (value && currentEpc && epcIndex(value) >= epcIndex(currentEpc)) {
setCurrentEpc("");
}
}
function apply() {
onApply({
@ -115,7 +119,7 @@ export default function PropertyFilters({
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm
bg-white focus:outline-none focus:ring-2 focus:ring-black/10"
value={currentEpc}
onChange={(e) => setCurrentEpc(e.target.value as any)}
onChange={(e) => handleCurrentEpcChange(e.target.value as any)}
>
<option value="">Any</option>
{["C", "D", "E", "F", "G"].map((epc) => (
@ -139,7 +143,7 @@ export default function PropertyFilters({
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm
bg-white focus:outline-none focus:ring-2 focus:ring-black/10"
value={expectedEpc}
onChange={(e) => setExpectedEpc(e.target.value as any)}
onChange={(e) => handleExpectedEpcChange(e.target.value as any)}
>
<option value="">Any</option>
{["A", "B", "C", "D"].map((epc) => (