Created
August 1, 2019 03:51
-
-
Save xinlc/477cce20e19f721b481396f4a2509be2 to your computer and use it in GitHub Desktop.
JS 防止快速重复点击
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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