文本字符串必须在 <Text> 组件中呈现。 (在世博会的 android 和 ios...运行 上)

Text strings must be rendered within a <Text> component. (on both android and ios...running in expo)

我正在尝试 运行 下面的代码,但它抛出错误“文本字符串必须在 <Text> 组件中呈现。”我现在正在使用 expo。它报告没有日志。日志部分为空。

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

export default function App() {
const [focusSubject, setFocusSubject] = useState(null);
return (
  <View style={styles.container}>
    focusSubject ? (
      <Text>Screen 1</Text>
    ) : (
      <Text>Screen 2</Text>
    )
  </View>
);
}

const styles = StyleSheet.create({
container: {
  flex: 1,
  backgroundColor: '#252250',
},
});

您需要在 {} 中使用条件。

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

export default function App() {
const [focusSubject, setFocusSubject] = useState(null);
return (
  <View style={styles.container}>
    {focusSubject ? (
      <Text>Where am I going to build a timer</Text>
    ) : (
      <Text />
    )}
  </View>
);
}

const styles = StyleSheet.create({
container: {
  flex: 1,
  backgroundColor: '#252250',
},
});