Skip to content

Instantly share code, notes, and snippets.

@xinlc
Created August 1, 2019 03:51
Show Gist options
  • Save xinlc/477cce20e19f721b481396f4a2509be2 to your computer and use it in GitHub Desktop.
Save xinlc/477cce20e19f721b481396f4a2509be2 to your computer and use it in GitHub Desktop.
JS 防止快速重复点击
let isCalled = false, timer;
/**
* @param functionTobeCalled 被包装的方法
* @param interval 时间间隔,可省略,默认600毫秒
*/
export default callOnceInInterval = (functionTobeCalled, interval = 600) => {
if (!isCalled) {
isCalled = true;
clearTimeout(timer);
timer = setTimeout(() => {
isCalled = false;
}, interval);
return functionTobeCalled();
}
};
import callOnceInInterval from './CallOnceInterval';
//...
onPress={activityId => callOnceInInterval(() => navigate('ActivityDetail', {'id': activityId}))}
//..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment