React Native 文本字符串必须在组件中呈现< Text>,in App(由withDevTools(App)创建)

ac1kyiln  于 2023-01-27  发布在  React
关注(0)|答案(2)|浏览(159)

我有一个原生的react应用程序。我有这些简单的对象:

export const AnimalGroupScreen = () => (
    <SafeAreaView style={styles.container}>
        <View style={styles.search}>
            <Searchbar />
        </View>
        <View style={styles.list}>
            <AnimalGroupInfo />
        </View>
    </SafeAreaView>
);
import React from "react";
import { Text } from "react-native";

export const AnimalGroupInfo = () => <Text> Hello there</Text>;

和应用程序:

import { AnimalGroupScreen } from "./src/features/animalGroup/screens/animal-group-screen";
/* eslint-disable prettier/prettier */
import ExpoStatusBar from "expo-status-bar/build/ExpoStatusBar";
import React from "react";

export default function App() {
    return (
        <>
            <AnimalGroupScreen />;
            <ExpoStatusBar style="auto" />
        </>
    );
}

但我仍然得到这个错误:

Error: Text strings must be rendered within a <Text> component.

This error is located at:
    in App (created by withDevTools(App))
    in withDevTools(App)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)

当然我搜索了这个错误。但是我在信息组件中只有一个文本标记。
这似乎是正确的。那么如何解决这个错误呢?

nafvub8i

nafvub8i1#

这里有一个分号:

<AnimalGroupScreen />;

把它拆下来,它应该能工作。

n53p2ov0

n53p2ov02#

删除;从<AnimalGroupScreen />;

相关问题