我使用 React Native 构建了自己的按钮组件,并尝试在我的代码中使用它。我现在要做的就是让它记录控制台消息,但由于某种原因它没有这样做。
按钮组件
import React, {Component} from 'react';
import { Text, TouchableOpacity } from 'react-native';
class Button extends Component {
render(){
const { onPress, children } = this.props;
const { buttonStyle, textStyle } = styles;
return (
<TouchableOpacity onPress={ onPress } style={ buttonStyle }>
<Text style={ textStyle }>
{ children }
</Text>
</TouchableOpacity>
);
}
}
使用按钮的代码
class FlashcardMenuDetail extends Component {
onButtonPress() {
console.log('You pushed the button');
}
render() {
const { title } = this.props.flashcard;
return (
<Card>
<CardItem>
<Button onpress={this.onButtonPress.bind(this)}>
{ title }
</Button>
</CardItem>
</Card>
);
}
}
我可以按下按钮,但控制台窗口上没有显示任何内容。