I have been making great progress and all of the sudden everything broke. I'm getting the following error message in my browser:
./src/PokedexSelector.js
Syntax error: Unexpected token (48:9)
46 |
47 |
> 48 | export default PokedexSelector;
| ^
49 |
This doesn't make any sense to me as I have tried changing many things in the code and looking for missing curly braces etc but cannot identify the source of trouble. Even when I change things, the error just jumps around. For example, if I remove the last line and refresh, I get this:
./src/PokedexSelector.js
Syntax error: Unexpected token (46:0)
44 | )
45 | }
> 46 |
| ^
...doesn't make any sense to me.
Here is the whole file:
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;
Add "}" after render. Class is still open.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.