Use React.Children.count()

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-09-14 17:19:57 +02:00
parent c460d56e50
commit b26bec949d
No known key found for this signature in database
GPG Key ID: 55C211A1226CB17D
1 changed files with 3 additions and 3 deletions

View File

@ -29,7 +29,7 @@ interface IProps {
// with no vertical scroll opportunity. // with no vertical scroll opportunity.
verticalScrollsHorizontally?: boolean; verticalScrollsHorizontally?: boolean;
children: JSX.Element | JSX.Element[]; children: React.ReactNode;
className: string; className: string;
} }
@ -65,8 +65,8 @@ export default class IndicatorScrollbar extends React.Component<IProps, IState>
}; };
public componentDidUpdate(prevProps: IProps): void { public componentDidUpdate(prevProps: IProps): void {
const prevLen = ("length" in prevProps?.children) ? prevProps.children.length : 0; const prevLen = React.Children.count(prevProps.children);
const curLen = ("length" in this.props?.children) ? this.props.children.length : 0; const curLen = React.Children.count(this.props.children);
// check overflow only if amount of children changes. // check overflow only if amount of children changes.
// if we don't guard here, we end up with an infinite // if we don't guard here, we end up with an infinite
// render > componentDidUpdate > checkOverflow > setState > render loop // render > componentDidUpdate > checkOverflow > setState > render loop