我对 react 还很陌生,所以如果问题非常愚蠢,请不要感到惊讶。当我保存代码时,我在终端中收到“意外 token ,预期,(24:2)”,请它指向 sendChat 函数。有关逗号缺失位置的任何线索;
componentDidUpdate(){
setInterval(()=>{
socket.on('chat',(data)=>{
history.push(data);
console.log(data);
},1000);
}
sendChat(){ // points to the beginning of this line
socket.emit('chat',{
message:this.state.message
});
}
最佳答案
componentDidUpdate(){
setInterval(()=>{
socket.on('chat',(data)=>{
history.push(data);
console.log(data);
}) //<--------
},1000);
}
您在指定位置缺少右大括号和圆括号
关于javascript - 找不到缺少的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49090529/