React Native error: Raw “ ” must be wrapped in an explicit Component

前端 未结 6 717
执笔经年
执笔经年 2021-01-19 14:27

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

Thank you

相关标签:
6条回答
  • 2021-01-19 14:52

    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>}
    
    0 讨论(0)
  • 2021-01-19 14:56

    I have already solved the problem, the answer is need to add a space:

     <View style={{width:40, height:40, backgroundColor:"green", margin:5}}>
                        <Text style={{fontSize:18}}>格子{this.state.size1}</Text>
                    </View>
    

    not

    格子{this.state.size1}

    0 讨论(0)
  • 2021-01-19 15:01

    You need to remove whitespace between tag. Take a look at each or put show whitespace in webstorm Preferences | Editor | General | Appearance

    0 讨论(0)
  • 2021-01-19 15:02

    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*/}
    
    0 讨论(0)
  • 2021-01-19 15:08

    I also encounter this error, but in my case I accidentally modified / auto formatted some .js files and messed up the JSX. And I cannot easily trace the source of the JSX component I messed up. The way I solved my problem surprisingly is to delete the node_module folder and reinstall all the node packages by npm install at the root folder of your project.

    0 讨论(0)
  • 2021-01-19 15:11

    On latest releases, you can try the following, getting stack traces

    0 讨论(0)
提交回复
热议问题