Skip to content

Commit

Permalink
fix(demo/text): check improvement removing negated conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilariaventurini committed Oct 8, 2020
1 parent 9f98551 commit 1d6b3f2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/visx-text/src/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,8 @@ class Text extends React.Component<TextProps, TextState> {
// 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,
Expand All @@ -138,7 +136,8 @@ class Text extends React.Component<TextProps, TextState> {
}

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 }] });
}

Expand Down

0 comments on commit 1d6b3f2

Please sign in to comment.