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

428
Vistas
Prevent multiple fast clicks from triggering API

For my project a instagram-clone, I have a like and dislike button. If there are no likes or dislikes from the current logged in user, both will show black. If I like the post the like will show blue, and then when I click dislike, it switches from like to dislike, from blue to red. And clicking which ever is activated like/dislike it will unlike or undislike. The problem that arises, is that when you click super fast it somehow breaks through and adds multiple likes, when each user should only be able to add one like or one dislike.

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Rate limiting example using Debouncing. If the user clicks fast multiple times only the last click will register. You can change the delay time as per your requirements.

const debounce = (fn, delay) => {
  let t = null;
  return function(...args) {
    clearTimeout(t);
    t = setTimeout(() => {
      fn(...args);
    }, delay);
  }
};

let handleLike = () => {
  console.log("Like Clicked");
};

handleLike = debounce(handleLike, 1000);

const btn = document.querySelector("#like");
btn.addEventListener("click", handleLike);
<button id="like">
  Like
</button>

over 4 years ago · Santiago Trujillo Denunciar
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