Skip to content

Commit

Permalink
fix(flat-components): test audio memory leak (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious authored Nov 15, 2022
1 parent 7122c90 commit 5946ea8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import stopSVG from "../icons/stop.svg";
import "./style.less";

import { Button } from "antd";
import React, { useRef, useState } from "react";
import React, { useEffect, useRef, useState } from "react";
import { Device } from "../constants";
import { DeviceTestSelect } from "../DeviceTestSelect";
import { useTranslate } from "@netless/flat-i18n";
Expand All @@ -30,6 +30,8 @@ export const SpeakerTest: React.FC<SpeakerTestProps> = ({
const [isPlaying, setIsPlaying] = useState(false);
const audioRef = useRef<HTMLAudioElement>(null);

useEffect(() => () => audioRef.current?.pause(), []);

const togglePlay = (): void => {
isPlaying ? audioRef.current?.pause() : audioRef.current?.play();
setIsPlaying(!isPlaying);
Expand Down

0 comments on commit 5946ea8

Please sign in to comment.