在 react-native 中我有这个类(来自 kittenTricks):
import {Platform} from 'react-native';
export class UIConstants {
static AppbarHeight = Platform.OS === 'ios' ? 44 : 56;
static StatusbarHeight = Platform.OS === 'ios' ? 20 : 0;
static HeaderHeight = UIConstants.AppbarHeight + UIConstants.StatusbarHeight;
}
类名:AppConstants.js
问题出在我尝试导出此类时。我收到此错误:
undefined is not an object(evaluating 'UIConstants.AppbarHeight')
最佳答案
你不能在声明中引用同一个类。尝试早点定义高度:
const appbarHeight = Platform.OS === 'ios' ? 44 : 56;
const statusbarHeight = Platform.OS === 'ios' ? 20 : 0;
export class UIConstants {
static AppbarHeight = appbarHeight;
static StatusbarHeight = statusbarHeight;
static HeaderHeight = appbarHeight + statusbarHeight;
}
关于javascript - 未定义不是对象 (UIConstants),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51591847/