javascript - 无法导出组件 React Native
问题描述
我是 React Native 的新手,并试图从 React 中实现我的一些知识,比如在这种情况下:函数组件。但是,在我稍微更改了布局之后,它显示了我没有导出组件的错误。这是错误:
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'.
这是组件的快照:
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;
导入 App.js 的文件是 node_modules/expo/AppEntry.js 中的 AppEntry.js,内容如下:
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import App from '../../src/App';
registerRootComponent(App);
有人对此有答案或有类似情况吗?任何信息都会有所帮助。谢谢
解决方案
这就是我的代码在第一个文件中的样子。
import {AppRegistry} from 'react-native';
import App from './App';
AppRegistry.registerComponent('App Name', () => App);
推荐阅读
- php - Laravel: How to implement if statement within {{ }}
- python - 循环中的函数导致无限循环
- javascript - 从脚本更改其值时,HTML文本框仅在单击时刷新?
- bash - How to check if user input is in correct format?
- php - ¿How to use "readfile" if my file is outside the current folder?
- java - How to use compareTo method with generic T type?
- angular - Angular material theme primary and accent same color
- postgresql - Postgres: column does not exist
- sql - How do I convert a Hive interval to number of seconds?
- c++ - cpprest-sdk: get the certificate to an open connection from within a HTTP listener and/or request handler (Linux)