【发布时间】:2020-06-25 07:34:44
【问题描述】:
我创建了一个自定义按钮组件以实现可重用性,这是我的按钮代码
export default function AppButton({ title, color = "", marginVertical = 0 }) {
return (
<TouchableHighlight
style={[
styles.button,
{ backgroundColor: colors[color], marginVertical: marginVertical }]}
>
<Text style={styles.text}>{title}</Text>
</TouchableHighlight>
);
}
这是我要在其中打印控制台 .log 的按钮
<AppButton
title="login"
onPress={() => console.log("email and password recieved")}
/>
【问题讨论】:
-
你为什么把 onPress 写成 'onPres[![enter image description here][1]][1]s' 这个?另一件事是我认为您没有在 AppButton 组件上收到此道具