react.js将多个参数传递给箭头函数

问题描述 投票:1回答:1

我想按如下所示将2个参数传递给箭头功能。

componentDidMount(){
 setInterval(this.refresh(this.state.firstName,this.state.lastName),1000);
}
refresh = (firstName,lastName)=>{
 console.log(firstName,lastName);
}

日志成功打印,但是时间间隔不起作用。我该如何解决?

parameters state render setinterval arrow-functions
1个回答
1
投票

反应框架自动将事件参数添加到箭头功能。因此,您应将其指定为以下函数:

refresh = (firstName,lastName)=>e=>{
 console.log(firstName,lastName);
}

希望对您有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.