简体   繁体   English

无法导出组件 React Native

[英]Cannot export component React Native

I am new to React Native and trying to implement some of my knowledge from React like in this case: the function component.我是 React Native 的新手,并试图从 React 中实现我的一些知识,例如在这种情况下:function 组件。 However, after I changed the layout a bit it shows an error in how I didn't export the component.但是,在我稍微更改了布局之后,它显示了我没有导出组件的错误。 Here's the error:这是错误:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of 'App'.

Here's a snapshot of the component:这是组件的快照:

import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import {
    StyleSheet,
    Text,
    View,
    Card,
    Background,
    Logo,
    Header,
    Title,
    Button,
    Divider,
} from "react-native";
import AudioRecorderPlayer, {
    AVEncoderAudioQualityIOSType,
    AVEncodingOption,
    AudioEncoderAndroidType,
    AudioSet,
    AudioSourceAndroidType,
} from "react-native-audio-recorder-player";

const App = () => {
    const [initialtime, setInitialTime] = useState({
        isLoggingIn: false,
        recordSecs: 0,
        recordTime: "00:00:00",
        currentPositionSec: 0,
        currentDurationSec: 0,
        playTime: "00:00:00",
        duration: "00:00:00",
    });
    const audioRecorderPlayer = new AudioRecorderPlayer();
    audioRecorderPlayer.setSubscriptionDuration(0.09);
    return (
        <Card
            style={{
                flex: 1,
                flexDirection: "row",
                alignItems: "center",
                alignContent: "center",
                alignSelf: "center",
            }}
        >
            <Background>
                <Logo />
                <Header>InstaPlayer</Header>
                <Title>{initialtime[2]}</Title>
            </Background>
        </Card>
    );
};

export default App;

The file which import the App.js is AppEntry.js within node_modules/expo/AppEntry.js has the following content:导入 App.js 的文件是 node_modules/expo/AppEntry.js 中的 AppEntry.js,内容如下:

import registerRootComponent from 'expo/build/launch/registerRootComponent';

import App from '../../src/App';

registerRootComponent(App);

Does anyone have an answer to this or had a similar case?有人对此有答案或有类似情况吗? Any information would help.任何信息都会有所帮助。 Thank you谢谢

Try this version试试这个版本

import { StatusBar } from "expo-status-bar";
import React, { useState } from "react";
import {
    StyleSheet,
    Text,
    View,
    Card,
    Background,
    Logo,
    Header,
    Title,
    Button,
    Divider,
} from "react-native";
import AudioRecorderPlayer, {
    AVEncoderAudioQualityIOSType,
    AVEncodingOption,
    AudioEncoderAndroidType,
    AudioSet,
    AudioSourceAndroidType,
} from "react-native-audio-recorder-player";

class App extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {

    const [initialtime, setInitialTime] = useState({
        isLoggingIn: false,
        recordSecs: 0,
        recordTime: "00:00:00",
        currentPositionSec: 0,
        currentDurationSec: 0,
        playTime: "00:00:00",
        duration: "00:00:00",
    });
    const audioRecorderPlayer = new AudioRecorderPlayer();
    audioRecorderPlayer.setSubscriptionDuration(0.09);

    return (
      <Card
            style={{
                flex: 1,
                flexDirection: "row",
                alignItems: "center",
                alignContent: "center",
                alignSelf: "center",
            }}
        >
            <Background>
                <Logo />
                <Header>InstaPlayer</Header>
                <Title>{initialtime[2]}</Title>
            </Background>
        </Card>
    );
  }
}

export default App;

This is what my code looks like for the first file.这就是我的代码在第一个文件中的样子。

import {AppRegistry} from 'react-native';
import App from './App';

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM