Skip to content
Advertisement

Fetch API Console data on webpage using axios

I created a simple date picker react js, after that I call API and get some data from API in the console, now I want to fetch API data on the web page.

Here is the code i used to call API function, I want map response data on a web page

JavaScript

Advertisement

Answer

Here is the explanation for this issue you can refer here,

JavaScript

add a state (add an object property to this.state) and inside the submit handler, after getting the response in Axios, use setState({[name of state]: response.data }).

That takes care of updating the state. As for where to display them, it is up to you.

You can copy the code anywhere inside the render method. If u want to display it under the form, paste it inside the div container after the form.

For better controlling of the state, you can check one of the state-management tools like redux or simply use global context and implement routing using react-router –

Credits to @MrCeRaYA

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement