题目来源及自己的思路
太短,谷歌无法搜索到
相关代码
http://taro-docs.jd.com/taro/...
class Title extends Component{
handleClick = (index) => (e) => {
e.stopPropagation()
this.setState({
currentIndex: index
})
}
render() {
const { currentIndex } = this.props;
return (
{/* 调用 `this.handleClick(currentIndex)` 会返回一个函数,这个函数可以访问到 `currentIndex` 同时也能满足 `onClick` 的签名 */}
<View onClick={this.handleClick(currentIndex)}>
</View>
)
}
}
其实这儿就是一个高阶函数的经典运用。
这儿使用高阶函数的目的是为了传递index索引值
现在回答你的问题,有参数与没参数的区别。如果你的事件执行函数使用到了event参数那么你就需要有参数,没有用到这个参数自然也就不需要带这个参数了。比如你代码里面阻止事件冒泡就需要带参数。