Javascript 不在嵌套的TouchableOpacity中按操作
嗨,我的自定义组件是这样用TouchableOpacity包装的Javascript 不在嵌套的TouchableOpacity中按操作,javascript,react-native,jsx,touchableopacity,Javascript,React Native,Jsx,Touchableopacity,嗨,我的自定义组件是这样用TouchableOpacity包装的 const profileOnClick = () => {
const profileOnClick = () => {
console.log('Card Clicked!');
};
export const InfluencerCard = props => {
const {influencer, navigation} = props;
return (
<TouchableOpacity onPress={() => profileOnClick()}>
<Card>
<Text>
{influencer.user.name}
</Text>
<Text>
{influencer.tags[0].name}
</Text>
</Card>
</TouchableOpacity>
);
};
const profileOnClick=()=>{
console.log('Card Clicked!');
};
导出常量影响卡=道具=>{
const{influencer,navigation}=props;
返回(
profileOnClick()}>
{influencer.user.name}
{influencer.tags[0].name}
);
};
在主屏幕中
<ScrollView>
{data.categoriesForHome.map(category => (
<Layout key={category.id}>
<Text>
{category.name}({category.total})
</Text>
<ScrollView horizontal={true}>
{category.influencerProfiles.map(profile => (
<View key={profile.id}>
<InfluencerCard influencer={profile} />
</View>
))}
</ScrollView>
</Layout>
))}
</ScrollView>
{data.categoriesForHome.map(category=>(
{category.name}({category.total})
{category.influencerProfiles.map(profile=>(
))}
))}
当我单击我的自定义组件影响者卡
时,它什么也不做。
我想知道这是因为该组件位于其他组件中,所以父组件块单击自定义组件。或者调用onPress函数是错误的
但我试着没有父组件,它是工作的。
我错过了什么?那是我的错误。问题不是源于代码或组件。 我使用@ui kitten/components中的卡片组件,它在场景后面实现了TouchableOpacity。所以我不需要再用TouchableOpacity来包装,所以就这么做吧
<Card onPress={() => profileClick()}></Card>
profileClick()}>