Skip to content

Commit 5bc95ae

Browse files
gvelez17claude
andcommitted
Fix React dependency array in VideoRecorder
- Move stopRecording before startRecording to avoid reference error - Add stopRecording to startRecording dependency array 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9f02e60 commit 5bc95ae

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/components/VideoRecorder/index.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ const VideoRecorder: React.FC<VideoRecorderProps> = ({
6969
}
7070
}, [])
7171

72+
// Stop recording
73+
const stopRecording = useCallback(() => {
74+
if (timerRef.current) {
75+
clearInterval(timerRef.current)
76+
timerRef.current = null
77+
}
78+
79+
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== 'inactive') {
80+
mediaRecorderRef.current.stop()
81+
}
82+
83+
// Stop all tracks
84+
if (streamRef.current) {
85+
streamRef.current.getTracks().forEach(track => track.stop())
86+
streamRef.current = null
87+
}
88+
}, [])
89+
7290
// Start recording
7391
const startRecording = useCallback(() => {
7492
if (!streamRef.current) return
@@ -108,25 +126,7 @@ const VideoRecorder: React.FC<VideoRecorderProps> = ({
108126
return newTime
109127
})
110128
}, 1000)
111-
}, [maxDuration])
112-
113-
// Stop recording
114-
const stopRecording = useCallback(() => {
115-
if (timerRef.current) {
116-
clearInterval(timerRef.current)
117-
timerRef.current = null
118-
}
119-
120-
if (mediaRecorderRef.current && mediaRecorderRef.current.state !== 'inactive') {
121-
mediaRecorderRef.current.stop()
122-
}
123-
124-
// Stop all tracks
125-
if (streamRef.current) {
126-
streamRef.current.getTracks().forEach(track => track.stop())
127-
streamRef.current = null
128-
}
129-
}, [])
129+
}, [maxDuration, stopRecording])
130130

131131
// Upload video to backend
132132
const uploadVideo = useCallback(async () => {

0 commit comments

Comments
 (0)