且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

React Native 中未定义的自定义组件

更新时间:2022-04-25 10:04:32

您正在使用 import React from react-native ,它实际上并不存在于 react-native 中.您应该 从 react 本身导入 React - 相反.我已经修复了下面的 SimpleButton 类.

You are using import React from react-native , which is not actually present within react-native. You should import React from react itself - instead. I've fixed the SimpleButton class below.

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

import React from 'react';

export default class Test extends React.Component{
  render(){
    return (
      <View>
        <Text>Simple Button</Text>
      </View>
    );
  }
}

您也可以添加以下内容 -> import {Component} from 'react'; 然后简单地将此功能用作 export default class Test extends Component{...代码>,

You could also just add the following -> import {Component} from 'react'; and then simply use this feature as export default class Test extends Component{...,

(注意这一行替换了我之前提到的 import React from 'react'solution )

( note this line replaces the import React from 'react'solution i mentioned before )

希望能帮到你