@colisweb/rescript-toolkit 2.37.0 → 2.38.0

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": "2.37.0",
3
+ "version": "2.38.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -242,3 +242,29 @@ let useOnClickOutside = (ref: React.ref<Js.Nullable.t<Dom.element>>, handler) =>
242
242
  }
243
243
 
244
244
  let useIntersection = ReactUse.useIntersection
245
+
246
+ let useIsVisibleOnViewport = (~options: option<ReactUse.intersectionOptions<'a>>=?, domRef) => {
247
+ let (isVisible, setIsVisible) = React.useState(() => false)
248
+ let intersection = useIntersection(
249
+ domRef,
250
+ options->Option.getWithDefault({
251
+ root: Js.Nullable.null,
252
+ rootMargin: "0px",
253
+ threshold: 1.,
254
+ }),
255
+ )
256
+
257
+ React.useEffect1(() => {
258
+ intersection
259
+ ->Js.Nullable.toOption
260
+ ->Option.forEach(intersection => {
261
+ if intersection.intersectionRatio >= 1. {
262
+ setIsVisible(_ => true)
263
+ }
264
+ })
265
+
266
+ None
267
+ }, [intersection])
268
+
269
+ isVisible
270
+ }