gpt4 book ai didi

reactjs - 如何在React.js中找到错误(“Unexpected token”)?

转载 作者:行者123 更新时间:2023-12-03 08:10:27 27 4
gpt4 key购买 nike

我一直在进步,突然间一切都崩溃了。我在浏览器中收到以下错误消息:

./src/PokedexSelector.js
Syntax error: Unexpected token (48:9)

46 |
47 |
> 48 | export default PokedexSelector;
| ^
49 |

这对我来说没有任何意义,因为我尝试更改代码中的许多内容并寻找缺少的花括号等,但无法确定问题的根源。即使当我改变事情时,错误也会跳来跳去。例如,如果我删除最后一行并刷新,则会得到以下信息:
./src/PokedexSelector.js
Syntax error: Unexpected token (46:0)

44 | )
45 | }
> 46 |
| ^

...对我来说毫无意义。

这是整个文件:
import React, { Component } from 'react';
import { capitalize } from './HelperFunctions';

class PokedexSelector extends Component {
constructor(props) {
super(props);
this.state = {value: "National", pokedexes: []};

this.handleChange = this.handleChange.bind(this);
this.generatePokedexList = this.generatePokedexList.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

generatePokedexList() {
const pokedexes = this.state.pokedexes;
fetch("https://pokeapi.co/api/v2/pokedex/")
.then(response => response.json())
.then(myJson => {
let results = myJson["results"];
results.forEach(function(pokedex) {
let pokedexName = pokedex["name"];
let pokedexLink = "https://pokeapi.co/api/v2/pokedex/" + pokedexName;
let pokedexDisplayName = capitalize(pokedexName.replace('-',' '));
pokedexes.push(
{
name: pokedexName,
"displayName": pokedexDisplayName,
"link": pokedexLink
}
);
});
})
}

render() {
this.generatePokedexList();
return (
<select id="pokedex-selector" value={this.state.value} onChange={this.handleChange()}>
<option> {capitalize(this.state.value)} </option>
</select>
)
}


export default PokedexSelector;

最佳答案

渲染后添加“}”。类仍然开放。

关于reactjs - 如何在React.js中找到错误(“Unexpected token”)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53310972/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com