diff --git a/src/components/hooks/useRect/index.tsx b/src/components/hooks/useRect/index.tsx index 33329237..8b619922 100644 --- a/src/components/hooks/useRect/index.tsx +++ b/src/components/hooks/useRect/index.tsx @@ -1,60 +1,55 @@ -import { useCallback, useLayoutEffect, useRef, useState } from "react"; +import { useCallback, useLayoutEffect, useRef, useState } from 'react' import ResizeObserver from 'resize-observer-polyfill' type RectResult = { - bottom: number; - height: number; - left: number; - right: number; - top: number; - width: number; -} | null; + bottom: number + height: number + left: number + right: number + top: number + width: number +} | null const getRect = (element: HTMLElement | null): RectResult | null => { - if (!element) return null; - return element.getBoundingClientRect(); -}; - -const useRect = (): [ - RectResult, - React.MutableRefObject -] => { - const ref = useRef(null); - const current = ref.current || null; - const [rect, setRect] = useState(getRect(current)); + if (!element) return null + return element.getBoundingClientRect() +} + +const useRect = (): [RectResult, React.MutableRefObject] => { + const ref = useRef(null) + const current = ref.current || null + const [rect, setRect] = useState(getRect(current)) const handleResize = useCallback(() => { - if (!ref.current) return; + if (!ref.current) return // Update client rect - setRect(getRect(ref.current)); - }, [ref]); + setRect(getRect(ref.current)) + }, [ref]) useLayoutEffect(() => { - const element = ref.current; - if (!element) return; + const element = ref.current + if (!element) return - handleResize(); - if (typeof ResizeObserver === "function") { - let resizeObserver: ResizeObserver | null = new ResizeObserver(() => - handleResize() - ); - resizeObserver.observe(element); + handleResize() + if (typeof ResizeObserver === 'function') { + let resizeObserver: ResizeObserver | null = new ResizeObserver(() => handleResize()) + resizeObserver.observe(element) return () => { - if (!resizeObserver) return; - resizeObserver.disconnect(); - resizeObserver = null; - }; + if (!resizeObserver) return + resizeObserver.disconnect() + resizeObserver = null + } } // set resize listener - window.addEventListener("resize", handleResize); + window.addEventListener('resize', handleResize) // remove resize listener - return () => window.removeEventListener("resize", handleResize); - }, [handleResize]); + return () => window.removeEventListener('resize', handleResize) + }, [handleResize]) - return [rect, ref]; -}; + return [rect, ref] +} export default useRect diff --git a/src/pages/home/index.jsx b/src/pages/home/index.jsx index 657b9197..1e5d687a 100644 --- a/src/pages/home/index.jsx +++ b/src/pages/home/index.jsx @@ -6,9 +6,9 @@ import CountUp from 'react-countup' // import { PinInput } from 'react-input-pin-code' import SpotlightCard from '@stateless/Spotlight' import Typewriter from 'typewriter-effect' -import Marquee from "react-fast-marquee" -import Masonry, { ResponsiveMasonry } from "react-responsive-masonry" -import useDetectScroll, { Direction } from "@smakss/react-scroll-direction" +import Marquee from 'react-fast-marquee' +import Masonry, { ResponsiveMasonry } from 'react-responsive-masonry' +import useDetectScroll, { Direction } from '@smakss/react-scroll-direction' import FixTabPanel from '@stateless/FixTabPanel' import TypedText from '@stateless/TypedText' import ReMarkdown from '@stateless/ReMarkdown' @@ -184,7 +184,7 @@ const Home = () => {
-
+
@@ -202,13 +202,11 @@ const Home = () => {

*/}
-

- React Animate On Scroll. -

+

React Animate On Scroll.

-

+

@@ -267,24 +265,36 @@ const Home = () => {
- -
+ +
-
+
dot mask
RectResult.
- width: {parseInt(barRect?.width)} height: {parseInt(barRect?.height)} top: {parseInt(barRect?.top)} bottom: {parseInt(barRect?.bottom)} right: {parseInt(barRect?.right)} left: {parseInt(barRect?.left)}
+ width: {parseInt(barRect?.width)} height: {parseInt(barRect?.height)} top: {parseInt(barRect?.top)} bottom:{' '} + {parseInt(barRect?.bottom)} right: {parseInt(barRect?.right)} left: {parseInt(barRect?.left)} +
@@ -299,17 +309,17 @@ const Home = () => {
water mark
mask
-
-
-
-
-
-
+
+
+
+
@@ -367,9 +377,7 @@ const Home = () => {
- + @@ -391,12 +399,36 @@ const Home = () => {
-
React
+
+ React +
-
Vue
+
+ Vue +