Javascript onClick()不';React本机应用程序中的t触发器功能
在我的react原生移动应用程序中,我在Row.js中编写了一个名为Row的组件,其中包含一个带有Javascript onClick()不';React本机应用程序中的t触发器功能,javascript,reactjs,react-native,Javascript,Reactjs,React Native,在我的react原生移动应用程序中,我在Row.js中编写了一个名为Row的组件,其中包含一个带有onClick()事件处理程序的TouchableOpacity。但是,当单击组件时,该函数不会运行 “行”组件显示有关特定胶片的一些文本,单击时应运行handlePress()函数: const Row = props => ( <TouchableOpacity onClick={() => props.handlePress(props.imdbID)} style={s
onClick()
事件处理程序的TouchableOpacity
。但是,当单击组件时,该函数不会运行
“行”组件显示有关特定胶片的一些文本,单击时应运行handlePress()函数:
const Row = props => (
<TouchableOpacity onClick={() => props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)
请有人告诉我我做错了什么以及为什么函数没有运行。React native没有
onClick
forTouchableOpacity
。
改用
onPress
。React Native不提供onClick
功能,而是提供onPress
,因此将onClick替换为onPress
const Row = props => (
<TouchableOpacity onPress={() => props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)
const Row=props=>(
props.handlePress(props.imdbID)}style={styles.row}>
一些文本
)
希望这能有所帮助,不要有任何疑问如果您查看,它没有onClick
你应该使用
const Row=props=>(
//使用onPress
props.handlePress(props.imdbID)}style={styles.row}>
一些文本
)
使用onPress()
而不是onClick()
改进的代码
const Row = props => (
<TouchableOpacity onPress={()=> props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)
const Row=props=>(
props.handlePress(props.imdbID)}style={styles.row}>
一些文本
)
使用onPress而不是onClick,并确保您是从react native而不是手势处理程序导入可触摸
const Row = props => (
<TouchableOpacity onPress={() => props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)
const Row = props => (
// using onPress
<TouchableOpacity onPress={() => props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)
const Row = props => (
<TouchableOpacity onPress={()=> props.handlePress(props.imdbID)} style={styles.row}>
<Text>Some text</Text>
</TouchableOpacity>
)