lodash library 就像这样。。。
<Button onPress={_.debounce( () => { navigation.goBack() }, 500, { leading: true, trailing: false, } )} title="Back" />
将去抖动函数的定义从“render”方法中移动,如下所示:
export default class YourClassName extends Component { constructor() { super(); this.debouncedOnPressHandler = _.debounce( () => { navigation.goBack() }, 500, { leading: true, trailing: false, } ) } render() { return ( <div> <Button onPress={this.debouncedOnPressHandler} title="Back A" /> <Button onPress={this.debouncedOnPressHandler} title="Back B" /> </div> ); } }