React Native error message: Trying to add a root view with an explicit id already set

前端 未结 3 786
时光说笑
时光说笑 2021-02-18 18:33

I am currently developing an application with React Native. The basis was Ignite. At the moment, very often when I start the application, I get an error message that I do not un

相关标签:
3条回答
  • 2021-02-18 18:40

    If you are getting something like the screenshot below , Please try reloading the app by tapping the reload button. I was getting this error if I made some changes in code that already had some exception/error.

    0 讨论(0)
  • 2021-02-18 18:49

    Shake the phone and you will get popup options, Stop the following things,

    • Debug JS Remotely
    • Disable Live Reload
    • Disable Hot Relaoding

    After that just reload the page, It will work.

    0 讨论(0)
  • 2021-02-18 18:51

    I noticed that this happens when you declare variables or properties after exporting your component. For example if you do the following:

    export default SignInLayout extends React.Component {
        render() {
            <Header />
            <Content />
            <Footer />
        }
    }
    
    const styles = Stylesheet.create({
        red: {
          color: red
        }
    });
    

    You get the error Trying to add a root view with an explicit id already set.

    To fix this, either move your variable declarations up, before exporting your component. Or You can still keep your variable declarations at the bottom by changing the above code to only export the component at the end.

    SignInLayout extends React.Component {
        render() {
            <Header />
            <Content />
            <Footer />
        }
    }
    
    const styles = Stylesheet.create({
        red: {
          color: red
        }
    });
    
    export default SignInLayout;
    
    0 讨论(0)
提交回复
热议问题