Skip to content

Commit fb6a7ce

Browse files
committed
fix: dependency array warnings
1 parent ff2aa2f commit fb6a7ce

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

src/components/DataTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const DataTable = <TData, TValue>({
9797
}
9898

9999
previousExpandedRef.current = expanded
100-
}, [expanded])
100+
}, [expanded, matomoEventCategory, table])
101101

102102
useEffect(() => {
103103
if (JSON.stringify(data) !== JSON.stringify(previousDataRef.current)) {
@@ -111,7 +111,7 @@ const DataTable = <TData, TValue>({
111111

112112
return () => clearTimeout(timer)
113113
}
114-
}, [data])
114+
}, [data, table])
115115

116116
return (
117117
<div className="relative">

src/components/ListenToPlayer/PlayerWidget/index.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef, useState } from "react"
1+
import { useCallback, useEffect, useRef, useState } from "react"
22
import { IoClose } from "react-icons/io5"
33

44
import {
@@ -75,27 +75,33 @@ const PlayerWidget = ({
7575
const [showSpeedMenu, setShowSpeedMenu] = useState(false)
7676
const speedMenuRef = useRef<HTMLDivElement>(null)
7777

78-
const calculateNewTime = (clientX: number) => {
79-
if (!scrubBarRef.current) return 0
80-
const rect = scrubBarRef.current.getBoundingClientRect()
81-
const position = Math.max(
82-
0,
83-
Math.min(1, (clientX - rect.left) / rect.width)
84-
)
85-
return duration * position
86-
}
78+
const calculateNewTime = useCallback(
79+
(clientX: number) => {
80+
if (!scrubBarRef.current) return 0
81+
const rect = scrubBarRef.current.getBoundingClientRect()
82+
const position = Math.max(
83+
0,
84+
Math.min(1, (clientX - rect.left) / rect.width)
85+
)
86+
return duration * position
87+
},
88+
[duration]
89+
)
8790

8891
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
8992
setIsDragging(true)
9093
const newTime = calculateNewTime(e.clientX)
9194
onSeek(newTime)
9295
}
9396

94-
const handleMouseMove = (e: MouseEvent) => {
95-
if (!isDragging) return
96-
const newTime = calculateNewTime(e.clientX)
97-
onSeek(newTime)
98-
}
97+
const handleMouseMove = useCallback(
98+
(e: MouseEvent) => {
99+
if (!isDragging) return
100+
const newTime = calculateNewTime(e.clientX)
101+
onSeek(newTime)
102+
},
103+
[isDragging, calculateNewTime, onSeek]
104+
)
99105

100106
const handleMouseUp = () => {
101107
setIsDragging(false)
@@ -110,7 +116,7 @@ const PlayerWidget = ({
110116
document.removeEventListener("mousemove", handleMouseMove)
111117
document.removeEventListener("mouseup", handleMouseUp)
112118
}
113-
}, [isDragging])
119+
}, [handleMouseMove, isDragging])
114120

115121
useEffect(() => {
116122
const handleClickOutside = (event: MouseEvent) => {

src/components/ListenToPlayer/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ const ListenToPlayer = ({ slug }: { slug: string }) => {
8686
}
8787
audioPlayer.unload()
8888
}
89+
// eslint-disable-next-line react-hooks/exhaustive-deps
8990
}, [currentTrackIndex])
9091

9192
useEffect(() => {
9293
if (sound && autoplay && isPlaying) {
9394
sound.play()
9495
}
96+
// eslint-disable-next-line react-hooks/exhaustive-deps
9597
}, [sound])
9698

9799
useEffect(() => {

src/components/ProductTable/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const ProductTable = <T,>({
9494
// TODO: Fix this, removed to avoid infinite re-renders
9595
// router.replace(pathname, undefined, { shallow: true })
9696
}
97+
// eslint-disable-next-line react-hooks/exhaustive-deps
9798
}, [router.query])
9899

99100
// Update or remove preset filters

src/components/Quiz/QuizWidget/useQuizWidget.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const useQuizWidget = ({
6464
setQuizData(quiz)
6565
}
6666

67+
// eslint-disable-next-line react-hooks/exhaustive-deps
6768
useEffect(initialize, [quizKey])
6869

6970
const currentQuestionIndex = userQuizProgress.length

src/components/Translatathon/CountdownBanner.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { useEffect, useState } from "react"
1+
import { useEffect, useMemo, useState } from "react"
22

33
import BannerNotification from "@/components/Banners/BannerNotification"
44

55
export const CountdownBanner = () => {
66
const [countdown, setCountdown] = useState("")
77

8-
const translatathonStartDate = new Date("August 9, 2024 12:00:00 UTC")
9-
const translatathonEndDate = new Date("August 18, 2024 12:00:00 UTC")
8+
const translatathonStartDate = useMemo(
9+
() => new Date("August 9, 2024 12:00:00 UTC"),
10+
[]
11+
)
12+
const translatathonEndDate = useMemo(
13+
() => new Date("August 18, 2024 12:00:00 UTC"),
14+
[]
15+
)
1016

1117
const calculateCountdown = (targetDate: Date) => {
1218
const currentTime = new Date()
@@ -36,7 +42,7 @@ export const CountdownBanner = () => {
3642
return () => {
3743
clearInterval(interval)
3844
}
39-
}, [])
45+
}, [translatathonEndDate, translatathonStartDate])
4046

4147
return new Date() < translatathonStartDate ? (
4248
<>

0 commit comments

Comments
 (0)