Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native error: Raw " " must be wrapped in an explicit <Text> Component

Tags:

react-native

enter image description here

Hi, I am having this error in react native and cannot figure out what is causing it. Help would be greatly appreciated.

Thank you

like image 212
Drew Avatar asked Nov 28 '22 00:11

Drew


2 Answers

The issue is whitespace. Using tabs however does not count as whitespace. Try removing the space between the tag and the comment in lines 32 and 37.

<View> {/*green*/}

should be either

<View>{/*green*/}

or

<View>
    {/*green*/}
like image 64
Malitta N Avatar answered Dec 23 '22 17:12

Malitta N


I encountered a similar error when checking whether to render a component in the following manner:

{somevariable && <Text>abcd</Text>}

Whenever somevariable was 0, that somevariable would be interpreted as something that was supposed to be rendered and thus 0 is an invalid React Element. To resolve this, I made sure that the first expression always evaluated to a boolean.

{!!somevariable && <Text>abcd</Text>}
like image 42
Evan Siroky Avatar answered Dec 23 '22 15:12

Evan Siroky