Inside the getData method, we have checked the condition with the javascript if-else statement that the data we are receiving is an array or not? if it’s an array we are using the React setState method to set the state data to response data we are receiving from the API, if the type of data we are receiving from the API is not an array we are setting the data state to a blank array and console.log with an error message. After that, we have created a custom function getData to fetch data from the API using Axios asynchronously. So what we are exactly doing in the above code? We have first declared our initial state data to a blank array inside the constructor method.
0 Comments
Leave a Reply. |