1
1
import { Box , Flex , Text , Button , Heading , Link } from '@chakra-ui/react' ;
2
2
import Spline from '@splinetool/react-spline' ;
3
- import { useState } from 'react' ;
3
+ import { useState , useEffect } from 'react' ;
4
+ import { useInView } from 'react-intersection-observer' ;
4
5
5
6
export const UpdatesSection = ( ) => {
6
7
const [ isSplineLoaded , setIsSplineLoaded ] = useState ( false ) ;
7
8
const [ splineError , setSplineError ] = useState ( false ) ;
9
+ const { ref, inView } = useInView ( {
10
+ threshold : 0.1 ,
11
+ rootMargin : '500px 0px 500px 0px' ,
12
+ } ) ;
13
+
8
14
9
15
function onSplineLoad ( ) {
10
16
setIsSplineLoaded ( true ) ;
@@ -20,16 +26,18 @@ export const UpdatesSection = () => {
20
26
'https://prod.spline.design/TmAYMNy2qJHyDE9m/scene.splinecode' ;
21
27
22
28
return (
23
- < Flex className = "relative bg-black min-h-screen" >
29
+ < Flex ref = { ref } className = "relative bg-black min-h-screen" >
24
30
< Box w = "50%" h = "full" maxH = "100%" >
25
- < Spline
26
- scene = { splineSceneUrl }
27
- onLoad = { onSplineLoad }
28
- onError = { onSplineError }
29
- className = "w-1/2 max-h-screen absolute top-0 left-0 z-0"
30
- />
31
+ { inView && (
32
+ < Spline
33
+ scene = { splineSceneUrl }
34
+ onLoad = { onSplineLoad }
35
+ onError = { onSplineError }
36
+ className = "w-1/2 max-h-screen absolute top-0 left-0 z-0"
37
+ />
38
+ ) }
31
39
32
- { ( ! isSplineLoaded || splineError ) && (
40
+ { ( ! isSplineLoaded || splineError || ! inView ) && (
33
41
< Box
34
42
position = "absolute"
35
43
top = "0"
0 commit comments