我有一个父组件,它创建一个将“onPress”传递给父组件的子组件,
工作正常,但现在需要将一些价值从孩子传递给父母......
父组件:
const filterBarTapped = ( index:any )=> {
console.log('tongo:', index )
}
const Charter = ({ isSingle, isDarkMode, data1, data2 }: Charterprops) => {
return (
<View>
{ Object.keys(data1).length > 6 && <TabBar data={data1} onPress={() => filterBarTapped()}/>} ...
孩子:
const handleClick = (index:any) => {
setSelectedTab(index)
console.log("sale index:", index)
onPress()
}
return (
<View style={{
flexDirection: "row",
justifyContent: 'space-around',
alignItems: 'center',
}}>
{tabs.map(p => (
<Tab
title={p.title}
onPress={() => handleClick(p.itemIndex)}
itemIndex={p.itemIndex}
selectedItem={selectedTab} />
))}
</View>
)
}
但我得到,
汤戈:未定义
那么,如何将索引传递给我的 onPress 的父级?
干杯