【发布时间】:2022-01-22 21:55:58
【问题描述】:
我正在尝试使用带油门的调整大小事件。但是,它不起作用。我尝试如下调试:
import {throttle} from 'lodash'
export function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: undefined,
height: undefined,
})
const handleResize = () => {
// handle resize code....
}
const onWindowResize = () => {
console.log('Throttle') // <-- this does print out
throttle(() => {
console.log('bam') // <-- this doesn't print out
}, 100)
}
useEventListener('resize', onWindowResize)
return windowSize
}
从上面的代码中可以看出,在使用来自lodash 的throttle 函数之前,我一直在尝试注销。它会打印出来,但throttle 本身的日志不会。有谁知道这可能是为什么以及如何解决这个问题?
【问题讨论】:
标签: javascript reactjs lodash