I have React component FetchQoute which is supposed to get response from the provided URL, but it shows undefined instead ?
class FetchQuote extends Component {
constructor(props) {
super(props);
this.state = {
jokes: []
};
}
componentDidMount() {
console.log(res.value); //undefined
axios.get('https://api.icndb.com/jokes/random')
.then((res) => {
this.setState({data:res.value.joke});//error TypeError: Cannot read property 'joke' of undefined
})
}
}
That URL can be easily tested in browser to return JSON data correctly, including res.value.joke
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…