Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw text must be wrapped in explicit <Text> component #15870

Closed
xahon opened this issue Sep 8, 2017 · 3 comments
Closed

Raw text must be wrapped in explicit <Text> component #15870

xahon opened this issue Sep 8, 2017 · 3 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@xahon
Copy link

xahon commented Sep 8, 2017

Is this a bug report?

yes

If you'll try to execute something like this

render () {
   let title = ""
   return (
    <View>
      { title &&
         <Text>{title}</Text>
      }
    </View>
   )
}

It will throw that error, because IMHO it parses text in quotes like boolean true and goes to the next chunk (View and Text) and renders it successfully, but if there if empty quotes it tries to set raw text in view element. Here if snack example https://snack.expo.io/BJnJJBg5Z

Have you read the Contributing Guidelines?

Yes

Environment

  1. react-native -v:
    react-native-cli: 2.0.1
    react-native: 0.45.1

  2. node -v:
    v7.10.1

  3. npm -v:
    4.2.0

  4. yarn --version:
    0.27.5

Then, specify:

  • Target Platform: Android
  • Development Operating System: Ubuntu 16.04
  • Build tools: Expo

Steps to Reproduce

https://snack.expo.io/BJnJJBg5Z

(Write your steps here:)

  1. just try this construction in render: <View>{ text && <Text>{text}</Text> }</View>, where text is empty string ""

Expected Behavior

wont render and no error occurs

(Write what you thought would happen.)

Actual Behavior

Error that is hard to discover

(Write what happened. Add screenshots!)

Reproducible Demo

https://snack.expo.io/BJnJJBg5Z

(Paste the link to an example project and exact instructions to reproduce the issue.)

I don't think it needs more explains :)

@chirag04
Copy link
Contributor

chirag04 commented Sep 8, 2017

this is expected behavior and the error you get is self explanatory. idk if there is anything to improve here. ("" && true) will return empty string in javascript which is why you see the error. you can do something like: { title ? <Text>{title}</Text> : null }

@chirag04 chirag04 closed this as completed Sep 8, 2017
@xahon
Copy link
Author

xahon commented Sep 10, 2017

@chirag04 Yes, thanks, i already understood that. I solve my issue with this approach:
{ !!title && <Text>title</Text> }

@sujitpk-perennial
Copy link

For me, the issue raised because I forgot to close the tag properly.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 8, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants