File tree Expand file tree Collapse file tree 1 file changed +22
-23
lines changed
packages/react-vant/src/components/hooks Expand file tree Collapse file tree 1 file changed +22
-23
lines changed Original file line number Diff line number Diff line change @@ -9,34 +9,33 @@ export default function useVisibilityChange(
99 const [ state , setState ] = useState < boolean > ( )
1010 useEffect ( ( ) => {
1111 // compatibility: https://caniuse.com/#feat=intersectionobserver
12- if ( ! inBrowser || ! window . IntersectionObserver ) {
13- return null
14- }
15- const observer = new IntersectionObserver (
16- entries => {
17- // visibility changed
18- onChange ?.( entries [ 0 ] . intersectionRatio > 0 )
19- for ( const entry of entries ) {
20- setState ( entry . isIntersecting )
21- }
22- } ,
23- { root : document . body }
24- )
12+ if ( ! ( ! inBrowser || ! window . IntersectionObserver ) ) {
13+ const observer = new IntersectionObserver (
14+ entries => {
15+ // visibility changed
16+ onChange ?.( entries [ 0 ] . intersectionRatio > 0 )
17+ for ( const entry of entries ) {
18+ setState ( entry . isIntersecting )
19+ }
20+ } ,
21+ { root : document . body }
22+ )
2523
26- const observe = ( ) => {
27- if ( target . current ) {
28- observer . observe ( target . current )
24+ const observe = ( ) => {
25+ if ( target . current ) {
26+ observer . observe ( target . current )
27+ }
2928 }
30- }
3129
32- const unobserve = ( ) => {
33- if ( target . current ) {
34- observer . unobserve ( target . current )
30+ const unobserve = ( ) => {
31+ if ( target . current ) {
32+ observer . unobserve ( target . current )
33+ }
3534 }
36- }
3735
38- observe ( )
39- return unobserve
36+ observe ( )
37+ return unobserve
38+ }
4039 } , [ target . current ] )
4140
4241 return [ state ] as const
You can’t perform that action at this time.
0 commit comments