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

前端 未结 3 850
时光说笑
时光说笑 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: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() {
            
    } } 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() {
            
    } } const styles = Stylesheet.create({ red: { color: red } }); export default SignInLayout;

提交回复
热议问题