@@ -17,6 +17,7 @@ type Context = {
1717 setStateRaw : Dispatch < SetStateAction < boolean > > ;
1818 containerRef : RefObject < HTMLDivElement > ;
1919 containerHeight : RefObject < "auto" | number > ;
20+ computeContainerHeight : ( ) => void ;
2021} ;
2122
2223const ChartTablePreviewContext = createContext < Context > ( {
@@ -25,6 +26,7 @@ const ChartTablePreviewContext = createContext<Context>({
2526 setStateRaw : ( ) => { } ,
2627 containerRef : { current : null } ,
2728 containerHeight : { current : "auto" } ,
29+ computeContainerHeight : ( ) => undefined ,
2830} ) ;
2931
3032export const useChartTablePreview = ( ) => {
@@ -52,13 +54,16 @@ export const ChartTablePreviewProvider = ({
5254 const [ state , setStateRaw ] = useState < boolean > ( false ) ;
5355 const containerHeight = useRef ( "auto" as "auto" | number ) ;
5456 const containerRef = useRef < HTMLDivElement > ( null ) ;
57+ const computeContainerHeight = ( ) => {
58+ if ( ! containerRef . current ) {
59+ return ;
60+ }
61+ const bcr = containerRef . current . getBoundingClientRect ( ) ;
62+ containerHeight . current = bcr . height ;
63+ } ;
5564 const setState = useCallback (
5665 ( v ) => {
57- if ( ! containerRef . current ) {
58- return ;
59- }
60- const bcr = containerRef . current . getBoundingClientRect ( ) ;
61- containerHeight . current = bcr . height ;
66+ computeContainerHeight ( ) ;
6267 return setStateRaw ( v ) ;
6368 } ,
6469 [ setStateRaw ]
@@ -71,6 +76,7 @@ export const ChartTablePreviewProvider = ({
7176 setStateRaw,
7277 containerRef,
7378 containerHeight,
79+ computeContainerHeight,
7480 } ;
7581 } , [ setState , state , containerRef , containerHeight , setStateRaw ] ) ;
7682 return (
0 commit comments