【发布时间】:2019-02-10 11:09:49
【问题描述】:
我的 FlatList 是无状态组件,当按下项目时,我想通过调用方法“handleOnPress”来处理 onPress。我该怎么做 ??
以下是示例代码。
`
handleOnPress = () => {
.....
}
<SampleListView
data={prop.data}
onPress={this.handleOnPress}
/>
const SampleListView = (props: Props) => {
return (
<FlatList
style={styles.container}
data={props.data}
keyExtractor={item => item.id.toString()}
renderItem={renderItem}
/>
)
}
renderItem = ({ item }: { item: DataSample }) => {
return (
<TouchableWithoutFeedback onPress={ () => props.onPress}>
....
</TouchableWithoutFeedback>
)
}
`
【问题讨论】:
-
也许这会对你有所帮助? stackoverflow.com/questions/45177077/…
标签: reactjs react-native react-native-ios react-native-flatlist