-
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.
Merge pull request #563 from blackLearning/feature/useClickAway
feat: support multiple target on useClickAway
- Loading branch information
Showing
5 changed files
with
72 additions
and
9 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,31 @@ | ||
/** | ||
* title: Custom multiple DOM target | ||
* desc: Support pass multiple DOM elements, or functions which returns the DOM element. | ||
* | ||
* title.zh-CN: 支持多个 DOM 对象 | ||
* desc.zh-CN: 支持传入多个目标对象。 | ||
*/ | ||
|
||
import React, { useState, useRef } from 'react'; | ||
import useClickAway from '../index'; | ||
|
||
export default () => { | ||
const [counter, setCounter] = useState(0); | ||
const ref1 = useRef(); | ||
const ref2 = useRef(); | ||
useClickAway(() => { | ||
setCounter((s) => s + 1); | ||
}, [ref1, ref2]); | ||
|
||
return ( | ||
<div> | ||
<button type="button" ref={ref1}> | ||
box1 | ||
</button> | ||
<button type="button" ref={ref2}> | ||
box2 | ||
</button> | ||
<p>counter: {counter}</p> | ||
</div> | ||
); | ||
}; |
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