You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-38Lines changed: 69 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,33 @@ const MyComponent = () => {
93
93
94
94
</details>
95
95
96
+
<details>
97
+
<summary>useClickOutside</summary>
98
+
99
+
A hook that fires a callback when a click (pointerdown) was registered outside of a component. Outside is defined as outside of your react tree, which means that this works with portals.
A hook that fires a callback when a click (pointerdown) was registered outside of a component. Outside is defined as outside of your react tree, which means that this works with portals.
184
+
A hook which detects if the browser and your page is in focus.
158
185
159
186
```tsx
160
-
import {useDraggable} from 'react-hooks-shareable'
187
+
import {useFocusDetection} from 'react-hooks-shareable'
161
188
162
189
const MyComponent = () => {
163
-
consthandler=useClickOutside(e=> {
164
-
console.log('Clicked outside!')
165
-
})
190
+
consthasFocus=useFocusDetection(1000)
166
191
167
-
return (
168
-
<divonPointerDown={handler}>
169
-
<span>Clicks here is inside</span>
170
-
{ReactDOM.createPortal(
171
-
<span>Clicks here are also inside</span>,
172
-
portalContainer
173
-
)}
174
-
</div>
175
-
)
192
+
return <span>{`User ${hasFocus?:'is' : 'is not'} focusing on this page`}</span>
176
193
}
177
194
```
178
195
179
196
</details>
180
197
181
198
<details>
182
-
<summary>useFocusDetection</summary>
199
+
<summary>useHasOverflow</summary>
183
200
184
-
A hook which detects if the browser and your page is in focus.
201
+
A hook for checking if an element has overflow.
185
202
186
203
```tsx
187
-
import {useFocusDetection} from 'react-hooks-shareable'
204
+
import {useHasOverflow} from 'react-hooks-shareable'
205
+
import {SomeComponent} from 'someComponentLibrary'
188
206
189
207
const MyComponent = () => {
190
-
consthasFocus=useFocusDetection(1000)
208
+
const{ hasOverflow, ref } =useHasOverflow()
191
209
192
-
return <span>{`User ${hasFocus?:'is' : 'is not'} focusing on this page`}</span>
0 commit comments