From 1d6b3f2aefc69bccf10281ddd5b6e51e3b15f1cc Mon Sep 17 00:00:00 2001 From: Ilaria Venturini Date: Thu, 8 Oct 2020 07:05:05 +0200 Subject: [PATCH] fix(demo/text): check improvement removing negated conditions --- packages/visx-text/src/Text.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/visx-text/src/Text.tsx b/packages/visx-text/src/Text.tsx index 23f6c5a60..a3683a8c0 100644 --- a/packages/visx-text/src/Text.tsx +++ b/packages/visx-text/src/Text.tsx @@ -115,10 +115,8 @@ class Text extends React.Component { // Only perform calculations if using features that require them (multiline, scaleToFit) if (props.width || props.scaleToFit) { if (needCalculate) { - const words: string[] = (props.children !== null && props.children !== undefined) - ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) - : []; - + const words: string[] = + props.children == null ? [] : props.children.toString().split(/(?:(?!\u00A0+)\s+)/); this.wordsWithWidth = words.map(word => ({ word, width: getStringWidth(word, props.style) || 0, @@ -138,7 +136,8 @@ class Text extends React.Component { } updateWordsWithoutCalculate(props: TextProps) { - const words = (props.children !== null && props.children !== undefined) ? props.children.toString().split(/(?:(?!\u00A0+)\s+)/) : []; + const words = + props.children == null ? [] : props.children.toString().split(/(?:(?!\u00A0+)\s+)/); this.setState({ wordsByLines: [{ words }] }); }