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

104
Vistas
React Native run function to increase variable while button is pressed

I have an api that decrease sound volume when a request is made. What I am looking to do is have the sound decrease when button is pressed in. The volume should continually decrease as the button is pressed in. When the button is release the sound volume will stop decreasing. The following code works however its not working smoothly. How can I make my function call to continually run into button is released.

const [volume, setVolume] = useState(0);

//  needs to run until button is released
useEffect(() => {
  let source = axios.CancelToken.source();

  axios.get(`${network}/volume=${volume}`, {
    cancelToken: source.token,
  });

  return function () {
    source.cancel("Cancelling in cleanup");
  };
}, [volume]);

const _handlePressIn = () => {
  timer.current = setInterval(() => setVolume((vol) => vol - 2), 60);
};

const _handlePressOut = () => {
  // stop setInterval so that volume does not increase
  clearInterval(timer.current);
};

<Pressable
  onPress={() => console.log("pressed")}
  onPressIn={() => _handlePressIn()}
  onPressOut={() => _handlePressOut()}
>
  <Text>Volume Up</Text>
</Pressable>;

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