I'm working on a project for school and I get this error for a non-render portion of my code.
fetchCharacterData = () => {
var encodedURI = window.encodeURI(this.props.uri);
return axios.get(encodedURI).then(response => {
this.setState(() => {
return {
characterData: response.data
};
});
});
};
It has a problem with the line that reads this.setState(() => { I tried the suggestions on the other questions and nothing seems to work with this line of code.
componentDidMount() {
this.fetchCharacterData();
console.log("MOUNT");
}
render() {
console.log(this.state.characterData);
if (this.state.characterData.length === 0) {
return <div>Failed to fetch data from server</div>;
}
const characters = this.state.characterData.map(character => {
return <div key={character.name}><em>: {character.name}</em>: {character.class} </div>
});
}
renderfunction? That's where this error would be caused. - Ross Allencharactersarray, but you are indeed notreturning anything from therendermethod on that path. - Bergi