In this tutorial we are going to learn about how to get jsonplaceholder data using axios in class component.
First of all, create a constructor and define state variables, with an empty array .
For getting data or we can say for doing an api’s request like get , post, put, delete . We can use axios . axios is a javascript library which is used for interacting with backend or making requests from backend to front end.
Axios is an npm package we can install using this command npm i axios.
First we want to import axios for our program.
For getting data from json we need to use lifecycle methods which is componentDidMount().
After using jsx inside the render method we can print all the data inside the placeholder by using map method.
Output:-
0 Comments