我正在尝试照常访问我的 styles
属性,但是,我遇到了一个错误: Cannot read property 'swipeButtonCommon' of undefined
。
好吧,我的styles
对象是定义的,无论如何swipeButtonCommon
:
const styles = StyleSheet.create({
...
swipeButtonCommon:{
backgroundColor: Color.listActionBackground
},
...
//swipeButtonLeft and swipeButtonRight are also defined
})
function SwipeButton(title:string, side: 'left' | 'center' | 'right'){
let styleClass: string | null = null;
if(side == 'left'){
styleClass = 'swipeButtonLeft';
}else if(side == 'right'){
styleClass = 'swipeButtonRight'
}
return (
<View style={[styles.swipeButtonCommon, styles[styleClass!]]}><Text>{title}</Text></View>
)
}
我在<View style={...}
行中遇到了错误,即使我有一个断点集,由于某种原因,它也没有击中。我已经清除了Metro Bundler Cache和Haste模块地图,尽管没有用,但我重新启动了几乎所有内容。我在做什么错?
我发现了这个问题。我正在使用通常不习惯的function ComponentName()
语法。我已经切换到常规的class ComponentName extends Component
语法,问题消失了。