From b26bec949d309c09074e11fe99723e806407b88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 14 Sep 2021 17:19:57 +0200 Subject: [PATCH] Use React.Children.count() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/IndicatorScrollbar.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/IndicatorScrollbar.tsx b/src/components/structures/IndicatorScrollbar.tsx index 56929763c9..85de659481 100644 --- a/src/components/structures/IndicatorScrollbar.tsx +++ b/src/components/structures/IndicatorScrollbar.tsx @@ -29,7 +29,7 @@ interface IProps { // with no vertical scroll opportunity. verticalScrollsHorizontally?: boolean; - children: JSX.Element | JSX.Element[]; + children: React.ReactNode; className: string; } @@ -65,8 +65,8 @@ export default class IndicatorScrollbar extends React.Component }; public componentDidUpdate(prevProps: IProps): void { - const prevLen = ("length" in prevProps?.children) ? prevProps.children.length : 0; - const curLen = ("length" in this.props?.children) ? this.props.children.length : 0; + const prevLen = React.Children.count(prevProps.children); + const curLen = React.Children.count(this.props.children); // check overflow only if amount of children changes. // if we don't guard here, we end up with an infinite // render > componentDidUpdate > checkOverflow > setState > render loop