javascript - Unexpected token, expected "," in JSX
问题描述
I am currently a student working on a react app, and keep getting returned syntax errors for unexpected tokens in my onSubmit() function. It wants commas instead of closing curly brackets, and I do not understand why. I add commas, swap out curly brackets for commas, then do it all over again to no avail. Any ideas where I might be making a mistake?
import React from 'react';
import axios from 'axios';
import Info from './Info';
export default class Search extends React.Component{
state = {
ingredientName: '',
};
change = e => {
this.setState({
[e.target.name] : e.target.value,
});
};
onSubmit() {
e.preventDefault();
const userInput = JSON.stringify(this.state);
axios.get(`https://www.recipepuppy.com/api/?i=${this.state}`).then((res) => {
console.log(res.data),
}
};
};
render(){
return (
<div>
<form>
<input name="ingredientName" placeholder="chicken, rice, tomatoes, etc" value={this.state.ingredientName} onChange={e => this.change(e)}/>
<button onClick={e => this.onSubmit(e)}>Submit</button>
</form>
</div>
)
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
解决方案
Update this line
console.log(res.data),
to be
console.log(res.data);
推荐阅读
- bash - “-bash: [git: command not found” 在 mac 上的 bash 脚本中
- html - 具有奇偶内容的 Flexbox 居中 div
- java - 持久化关联实体时违反休眠约束
- clone - 在 love2d 中克隆一个夹具
- here-api - HERE 地图:缓存地理编码结果
- javascript - 多个服务人员处理推送通知
- python - 如何从python中的表中访问列数据?
- python - python有没有办法在几秒钟后隐藏画布?
- php - Laravel 作业(队列)不起作用
- .net-core - 如何从 .Net Core 中的 AppSettings 读取自定义类型?