'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>;



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source