From fa240716829d62cf76ae2cfa6d68ad1fa67f2ac7 Mon Sep 17 00:00:00 2001 From: luizcieslak Date: Wed, 8 Jul 2020 10:42:14 -0300 Subject: [PATCH] feat(useGrid): fallback size when containerWidth is 0 --- src/useGrid.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/useGrid.js b/src/useGrid.js index e7c27b36..003cfaf7 100644 --- a/src/useGrid.js +++ b/src/useGrid.js @@ -211,7 +211,13 @@ export default function useGrid({ locale, month: currentMonth, onMonthChange, tr useEffect(() => { const handleResize = () => { const containerElement = containerElementRef.current - const containerWidth = containerElement.offsetWidth + let containerWidth = containerElement.offsetWidth + + // Element is not rendered yet. Therefore, a fallback size must be provided + if (containerWidth === 0) { + containerWidth = Math.min(window.innerWidth, 548) + } + const cellWidth = containerWidth / 7 let newCellHeight = 1 let wide = false