title: Unable to pause React audio
body: <pre><code>import { useState } from &quot;react&quot;;
  
  function Music(){
  
    const [pauseToggle, setpauseToggle] = useState(false)
  
    const music = new Audio(require(`./Alan.mp3`));
    console.log(music);
    let isPlaying = false;
  
    const player = () =&gt; {
      pauseToggle ? setpauseToggle(false) : setpauseToggle(true);
      if(isPlaying){
        music.pause();
        isPlaying = false;
      }else{
        music.play();
        isPlaying = true;
      }
    }
  
    return(
      &lt;div&gt;
        &lt;button onClick={player}&gt;{pauseToggle?&quot;=&quot;:&quot;&gt;&quot;}&lt;/button&gt;
      &lt;/div&gt;
    )
  
  }
  
  export default Music;
  </code></pre>
  <p>I'm unable to pause the audio. IInstead it gets played twice when I try to pause.</p>
  <p>I tried to get help from this <a href="https://stackoverflow.com/questions/63003690/unable-to-pause-audio-in-reactjs">Unable to pause audio in Reactjs</a> but it didn't help.</p>
  <p>Any other solution for pausing audio file?</p>