@colisweb/rescript-toolkit 5.42.9 → 5.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "5.42.9",
3
+ "version": "5.43.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -451,3 +451,30 @@ let usePromiseV3 = (~debounce=true, fn, deps) => {
451
451
 
452
452
  (state, cancel)
453
453
  }
454
+
455
+ type scrollPosition = {
456
+ x: float,
457
+ y: float,
458
+ }
459
+
460
+ let useScrollPosition = (~delay=150, ()) => {
461
+ let (scrollPos, setScrollPos) = React.useState(() => {x: 0.0, y: 0.0})
462
+
463
+ React.useEffect(() => {
464
+ let handleScroll = () => {
465
+ setScrollPos(_ => {x: Browser.Window.scrollX, y: Browser.Window.scrollY})
466
+ }
467
+
468
+ let debouncedScroll = Lodash.throttle(handleScroll, delay)
469
+
470
+ Browser.Window.addEventListener("scroll", debouncedScroll)
471
+
472
+ Some(
473
+ () => {
474
+ Browser.Window.removeEventListener("scroll", debouncedScroll)
475
+ },
476
+ )
477
+ }, [delay])
478
+
479
+ scrollPos
480
+ }
@@ -187,6 +187,10 @@ module FormData = {
187
187
  }
188
188
 
189
189
  module Window = {
190
+ @val
191
+ external scrollX: float = "window.scrollX"
192
+ @val
193
+ external scrollY: float = "window.scrollY"
190
194
  @val
191
195
  external addEventListener: (string, ReactEvent.Form.t => unit) => unit = "window.addEventListener"
192
196
  @val
@@ -167,6 +167,10 @@ module FormData: {
167
167
  }
168
168
 
169
169
  module Window: {
170
+ @val
171
+ external scrollX: float = "window.scrollX"
172
+ @val
173
+ external scrollY: float = "window.scrollY"
170
174
  @val
171
175
  external addEventListener: (string, ReactEvent.Form.t => unit) => unit = "window.addEventListener"
172
176
  @val
@@ -21,3 +21,5 @@ external chunk: (array<'a>, int) => array<array<'a>> = "chunk"
21
21
  external isEmpty: 'a => bool = "isEmpty"
22
22
  @module("lodash/debounce")
23
23
  external debounce: ('a => unit, int) => 'b = "default"
24
+ @module("lodash/throttle")
25
+ external throttle: ('a => unit, int) => 'b = "default"