[英]How can I fix this error coming from eslint?
Is there a better way to write this part of the code?有没有更好的方法来编写这部分代码? It works, but the eslint is complaining that
它有效,但 eslint 抱怨说
'resp' is already declared in the upper scope 'resp' 已经在上层作用域中声明
In this part在这部分
return parseJSON(resp).then((resp) => {
throw resp
})
This is the entire code这是整个代码
componentDidMount = async () => {
const parseJSON = (resp) => (resp.json ? resp.json() : resp)
const checkStatus = (resp) => {
if (resp.status >= 200 && resp.status < 300) {
return resp
}
return parseJSON(resp).then((resp) => {
throw resp
})
}
const headers = {
'Content-Type': 'application/json'
}
try {
const data = await fetch('http://myurl/api', {
method: 'GET',
headers: headers
}).then(checkStatus)
.then(parseJSON)
this.setState({ data })
} catch (error) {
this.setState({ error })
}
}
You have variable name resp
in twice in the same scope on below lines:您在以下几行的同一范围内有两次变量名称
resp
:
const checkStatus = (resp) => {
and return parseJSON(resp).then((resp) => {
.并
return parseJSON(resp).then((resp) => {
.
change one of resp.更改其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.