Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda