Skip to content

Commit 269c59e

Browse files
committed
fix: Fix ESLint errors and remove unused imports
- Replace useEffect with useLayoutEffect in FilterInputField to fix setState-in-effect warning - Optimize dependency array in useLayoutEffect - Remove unused DialogClose import from ImageViewer
1 parent 747f0dc commit 269c59e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/components/FilterInput.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {memo, useCallback, useEffect, useRef, useState} from 'react'
1+
import {memo, useCallback, useLayoutEffect, useRef, useState} from 'react'
22

33
import {Filter as FilterIcon, HelpCircle, X as XIcon} from 'lucide-react'
44
import {Input} from '@/components/ui/input'
@@ -63,12 +63,17 @@ const FilterInputField = memo(
6363
}: FilterInputFieldProps) {
6464
const [localValue, setLocalValue] = useState(initialValue)
6565

66-
useEffect(() => {
67-
setLocalValue(initialValue)
68-
if (inputRef.current) {
69-
inputRef.current.value = initialValue
66+
// Sync localValue with initialValue when it changes
67+
// Note: This pattern is necessary to sync external prop changes to internal state
68+
useLayoutEffect(() => {
69+
if (localValue !== initialValue) {
70+
setLocalValue(initialValue)
71+
if (inputRef.current) {
72+
inputRef.current.value = initialValue
73+
}
7074
}
71-
}, [initialValue, inputRef])
75+
// eslint-disable-next-line react-hooks/exhaustive-deps
76+
}, [initialValue])
7277

7378
const handleKeyDown = useCallback(
7479
(e: React.KeyboardEvent<HTMLInputElement>) => {

src/components/ImageViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ZoomOut,
1010
RotateCcw,
1111
} from 'lucide-react'
12-
import {Dialog, DialogClose, DialogPortal} from '@/components/ui/dialog'
12+
import {Dialog, DialogPortal} from '@/components/ui/dialog'
1313
import * as DialogPrimitive from '@radix-ui/react-dialog'
1414
import {Button} from '@/components/ui/button'
1515
import {cn, createRawImageUrl, getMcmetaPath} from '@/utils'

0 commit comments

Comments
 (0)