Invariant Violation: Text strings must be rendered within a component

前端 未结 24 829
耶瑟儿~
耶瑟儿~ 2020-12-08 12:59

I\'ve upgraded from RN 0.54 to 0.57 and my app has pretty much fallen over due to using React Native Elements.

I took use of their error functionality on TextI

相关标签:
24条回答
  • 2020-12-08 13:35

    In my case, this error occurred due to the presence of semi-colon ';' at the end of the closing of Text tag. For all those who don't get the appropriate answer above, try this. By removing semi-colon, the error disappeared.

    0 讨论(0)
  • 2020-12-08 13:36

    try this :

    <>
        <View>
        {this.state.error &&
          <Text>
            Error message: {this.state.error}
        </Text>
       </View>
    </>
    
    0 讨论(0)
  • 2020-12-08 13:36

    I had the same problem, In my case I had an <AppText> component which shows simple formatted <Text> under the hood.

    First code was like

    <AppText> </AppText>

    while I was trying different things I just wrote it with self-closing syntax

    <AppText />

    then problem was suddenly solved.

    I think it was just about a special & invisible character I wrote between tags by mistake or this character was coming from VSCode by auto-complete feature or snippets, because I couldn't repeat the error by placing a space.

    0 讨论(0)
  • 2020-12-08 13:37
     <React.Fragment>
          {this.props.title ? (
            <React.Fragment> 
              <Text>  true </Text>
            </React.Fragment>
            ):(             
               <React.Fragment> 
              <Text>  false </Text>
              <Text>  false </Text>
            </React.Fragment>
    

    You have to wrap with View tag or React.Fragment tag and inside you need also wrap if element more then one

    0 讨论(0)
  • 2020-12-08 13:38
    this.state.recording ?(<Text>{this.secondsToMMSS(this.state.seconds)}</Text>) :                                     (null)
    

    text string must be rendered with in component

    0 讨论(0)
  • 2020-12-08 13:39

    This usually happens when you do inline conditional rendering. You should delete white space between Text and your condition like below.

    { this.state.event.cards[i].fields[j].error && <Text style={{ color: '#e74c3c', fontSize: 14, paddingLeft: 5 }}>
        {this.state.event.cards[i].fields[j].error}
      </Text>
    }
    
    0 讨论(0)
提交回复
热议问题