未找到不变违规视图配置 [英] invariant violation view config not found

查看:60
本文介绍了未找到不变违规视图配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行代码时,出现此错误:

未找到不变违规视图配置

index.js 代码是:

import { AppRegistry, Text, Image, View } from 'react-native';import React, { Component } from 'react';从 './src/codes/main' 导入 main;类应用程序扩展组件{使成为(){返回 <main/>;}}AppRegistry.registerComponent('app', () => app);

main.js 代码是:

import React, { Component } from 'react';从'react-native'导入{文本,视图};导出默认类 main 扩展组件{使成为(){返回 (<查看><Text>Salam</Text></查看>);};}

请帮忙

解决方案

组件名称必须大写,这是 React Native 中的语法要求.

<块引用>

index.js

import { AppRegistry, Text, Image, View } from 'react-native';import React, { Component } from 'react';从 './src/codes/main' 导入 Main;类 App 扩展组件{使成为(){返回 <Main/>;}}AppRegistry.registerComponent('App', () => App);

<块引用>

main.js

import React, { Component } from 'react';从'react-native'导入{文本,视图};导出默认类 Main 扩展组件{使成为(){返回 (<查看><Text>Salam</Text></查看>);};}

When i run the code, i get this error:

invariant violation view config not found

index.js code is :

import { AppRegistry, Text, Image, View } from 'react-native';
import React, { Component } from 'react';
import main from './src/codes/main';


class app extends Component{

  render(){
    return <main/>;
  }

}


AppRegistry.registerComponent('app', () => app);

main.js code is :

import React, { Component } from 'react';
import { Text, View } from 'react-native';


export default class main extends Component{
  render(){
    return (
      <View>
        <Text>Salam</Text>
      </View>
    );
  };
}

please help

解决方案

The component names must be capitalized as a syntax requirement in React Native.

index.js

import { AppRegistry, Text, Image, View } from 'react-native';
import React, { Component } from 'react';
import Main from './src/codes/main';


class App extends Component{

  render(){
    return <Main/>;
  }

}


AppRegistry.registerComponent('App', () => App);

main.js

import React, { Component } from 'react';
import { Text, View } from 'react-native';


export default class Main extends Component{
  render(){
    return (
      <View>
        <Text>Salam</Text>
      </View>
    );
  };
}

这篇关于未找到不变违规视图配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆