Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda