I have ajax functions in an api to which I'm making an axios get request from my react js component. How can I access the returned data to display it on the web page.
Depends of what you trying to do but this is a example.
componentDidMount() {
axios
.get(`endpoint`)
.then(res => this.setState({ posts: res.data }))
.catch(err => console.log(err))
}
A good way too should be if you using react-router to make the ajax call with the onEnter api from the router.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With