CSS 使人抓狂

This commit is contained in:
CrescentLeaf
2025-04-20 00:58:52 +08:00
parent 65ff48dabc
commit f305225eb3
8 changed files with 242 additions and 28 deletions

View File

@@ -0,0 +1,17 @@
/**
* @callback callback
* @param { Event } event
*/
/**
* 绑定事件
* @param { React.Ref } ref
* @param { String } eventName
* @param { callback } callback
*/
export default function useEventListener(ref, eventName, callback) {
React.useEffect(() => {
ref.current.addEventListener(eventName, callback)
return () => ref.current.removeEventListener(eventName, callback)
}, [ref, eventName, callback])
}