Turns out throttle()
from lodash was the correct way to go. To solve this problem I ensured that the options for the trailing edge were set to false:
const handleClick = _.throttle(
(index: number) => {
if (active === undefined) {
setActive(index);
return;
}
setActive(undefined);
},
200,
{ trailing: false },
);