Clear interval when functional connectionBauble gets unmounted

This commit is contained in:
Zoë Hoekstra 2022-08-11 19:44:55 +02:00
parent a6ee9a8c76
commit 765cfd0c9a
No known key found for this signature in database
GPG Key ID: F9B7B7D8130F3323

@ -8,9 +8,10 @@ export const ConnectionBauble = (props: baubleProps): React.ReactElement => {
const [connection, setConnection] = useState(props.callback()); const [connection, setConnection] = useState(props.callback());
useEffect(() => { useEffect(() => {
setInterval(() => { const timer = setInterval(() => {
setConnection(props.callback()); setConnection(props.callback());
}, 1000); }, 1000);
return () => clearInterval(timer);
}); });
return <div className="ConnectionBauble">{connection ? "Connected" : "Disconnected"}</div>; return <div className="ConnectionBauble">{connection ? "Connected" : "Disconnected"}</div>;