AJAX call in React

AJAX stands for Asynchronous JavaScript and XML. It is a technique used to make webpages faster to use and more interactive.

React itself doesn’t have any allegiance to any particular way of fetching data. React simply renders components, using data from only two places: props and state. To use some data from the server, you need to get that data into your components’ props or state.

So, How can you make an AJAX call in React?


You have to depend on the Third-party AJAX library.

  • Axios  –   If you feel comfortable working with JavaScript Promises You can use Axios.
  • You can use the browser fetch API
  • You can also use jQuery, but it’s not a good decision to include the whole library just for making API calls.
  • You hate promises but love callback then you can use superagent

Where to make an AJAX request?

You should populate data with AJAX calls in the componentDidMount  lifecycle method.

Check the official website for more details

https://reactjs.org/docs/faq-ajax.html

 

4 thoughts on “AJAX call in React”

Leave a Reply

Your email address will not be published. Required fields are marked *