Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
How to play sounds correctly?

I need to run sounds automatically in React. In order to run sounds, I use a non-standard useSound hook. It creates a button and by clicking on this button the sound starts. I made a trigger to automatically start a click and made a delay between sounds.

Sounds come in view of the array. Therefore, I go through the array and create several buttons that should be clicked. Tell me how to create for each button const [play] = useSound("/static/1.mp3"); and your unique id so that all buttons are automatically created and played?

import React, { useState, useEffect } from "react";

import useSound from "use-sound";

export default function Play(props) {

  const arr = ['./1.mp3', '/static/2.mp3', '/static/3.mp3']

  function Button() {
    return props.newResult.map(() => (
      <button className={styles.buttonPlay} id='button3'>
        {props.newResult}
      </button>
    ));
  }

  const Play = () => {
    const [play] = useSound("/static/1.mp3"); // Буква
    return (
      <>
        <button className={styles.buttonPlay} id='button' onClick={play}>
          Пациент
        </button>
      </>
    );
  };

  async function Auto() {
    await new Promise(function (s) {
      setTimeout(s, 1000);
    });
    document.querySelector("#button").click();

    await new Promise(function (s) {
      setTimeout(s, 1000);
    });
  }

  useEffect(() => {
    Auto();
  }, []);

  return (
    <>
      {Play()}
    </>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!