-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for array as event parameter in useEventListener (#2598)
* style: change the default import to import on demand * feat: support for array as event parameter in useEventListener * feat: review后修改 --------- Co-authored-by: lxr <[email protected]>
- Loading branch information
Showing
5 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* title: Listen to multiple events. | ||
* desc: Mouse hover or over the button to preview. | ||
* | ||
* title.zh-CN: 监听多个事件 | ||
* desc.zh-CN: 鼠标移入移出按钮查看效果。 | ||
*/ | ||
|
||
import React, { useRef, useState } from 'react'; | ||
import { useEventListener } from 'ahooks'; | ||
|
||
export default () => { | ||
const ref = useRef(null); | ||
const [value, setValue] = useState(''); | ||
|
||
useEventListener( | ||
['mouseenter', 'mouseleave'], | ||
(ev) => { | ||
setValue(ev.type); | ||
}, | ||
{ target: ref }, | ||
); | ||
|
||
return ( | ||
<button ref={ref} type="button"> | ||
You Option is {value} | ||
</button> | ||
); | ||
}; |
This file contains 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
This file contains 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
This file contains 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