Skip to content

Instantly share code, notes, and snippets.

@gayapedro
Created August 24, 2021 15:05
Show Gist options
  • Save gayapedro/eb55d8861f924bad60dca04a0455f6ed to your computer and use it in GitHub Desktop.
Save gayapedro/eb55d8861f924bad60dca04a0455f6ed to your computer and use it in GitHub Desktop.
import { toast } from 'react-toastify';
import { useState, useEffect } from 'react';
function Componente() {
const [toastAudio, setToastAudio] = useState(false);
const chamadaApi = async () => {
//...
toast.error();
setToastAudio(true);
//...
};
useEffect(() => {
if (toastAudio) {
const id = setTimeout(() => {
setToastAudio(false);
});
return () => clearTimeout(id);
}
}, [toastAudio]);
return (
//...
{toastAudio && <audio autoplay loop>
<source src='audio_file.mp3' type='audio/mpeg' />
</audio>}
//...
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment