【问题标题】:ReferenceError: Expo is not defined-React-NativeReferenceError: Expo is not defined-React-Native
【发布时间】:2020-07-07 16:52:47
【问题描述】:

我是 react-native 的新手。我试图在我的代码中使用 EXPO。但它说的是 ReferenceError: Expo is not defined-React-Native

 class Main extends Component {
  
  render() {
 
    return (
      <View style={{flex:1, paddingTop: Platform.OS === 'ios' ? 0 : Expo.Constants.statusBarHeight }}>
     
     </View>
    );
  }
}

【问题讨论】:

    标签: javascript reactjs react-native frontend expo


    【解决方案1】:

    像expo install expo-constants这样安装expo常量。

    import Constants from 'expo-constants';
    
    class Main extends Component {
      render() {
        return (
          <View
            style={{
              flex: 1,
              paddingTop: Platform.OS === 'ios' ? 0 : Constants.statusBarHeight,
            }}
          />
        );
      }
    }
    

    来源:https://docs.expo.io/versions/latest/sdk/constants/

    【讨论】:

      【解决方案2】:

      就像 Bas van der Linden 所说,您需要导入常量。

      import { Constants } from 'expo';
      

      但你还需要从 react-native 导入 Platform

      import { Platform } from 'react-native';
      

      【讨论】:

        猜你喜欢
        • 2019-12-02
        • 1970-01-01
        • 1970-01-01
        • 2020-10-22
        • 1970-01-01
        • 1970-01-01
        • 2021-09-14
        • 1970-01-01
        • 2014-03-03
        相关资源
        最近更新 更多