-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Table): fix
flexGrow
is invalid when the table is hidden and th…
…en shown
- Loading branch information
Showing
6 changed files
with
156 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useState, useEffect, RefObject } from 'react'; | ||
|
||
/** | ||
* useIntersectionObserver Hook | ||
* | ||
* @param ref - Ref object of the element to be observed | ||
*/ | ||
const useIntersectionObserver = (ref?: RefObject<HTMLElement>): boolean => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
// Check if the browser supports IntersectionObserver | ||
if (!('IntersectionObserver' in window)) { | ||
// If not supported, optionally set to visible or handle fallback logic | ||
setIsVisible(true); // Fallback: Set to visible | ||
return; | ||
} | ||
|
||
// Create an IntersectionObserver instance | ||
const observer = new IntersectionObserver(entries => { | ||
entries.forEach(entry => { | ||
setIsVisible(entry.isIntersecting); | ||
}); | ||
}); | ||
|
||
const element = ref?.current; | ||
|
||
// Start observing the target element | ||
if (element) { | ||
observer.observe(element); | ||
} | ||
|
||
// Cleanup function to unobserve the element when the component unmounts or dependencies change | ||
return () => { | ||
if (element) { | ||
observer.unobserve(element); | ||
} | ||
}; | ||
}, [ref]); | ||
|
||
return isVisible; | ||
}; | ||
|
||
export default useIntersectionObserver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters