Create React App

Create React App

  • Getting started
  • Help
  • GitHub

›Back-End Integration

Welcome

  • About The Docs

Getting Started

  • Getting Started
  • Folder Structure
  • Available Scripts
  • Browsers & Features
  • Updating To New Releases

Development

  • Editor Setup
  • Developing Components In Isolation
  • Analyzing Bundle Size
  • HTTPS In Development

Styles and Assets

  • Adding Stylesheets
  • Adding CSS Modules
  • Adding Sass Stylesheets
  • Post-Processing CSS
  • Adding Images, Fonts, And Files
  • Using The public Folder
  • Code Splitting

Building your App

  • Installing A Dependency
  • Importing A Component
  • Using Global Variables
  • Adding Bootstrap
  • Adding Flow
  • Adding Relay
  • Adding A Router
  • Environment Variables
  • Making A Progressive Web App

Testing

  • Running Tests
  • Debugging Tests

Back-End Integration

  • Proxying In Development
  • Fetching Data
  • Integrating With An API
  • Title & Meta Tags

Deployment

  • Deployment

Advanced Usage

  • Can I Use Decorators?
  • Pre-Rendering Static HTML
  • Advanced Configuration
  • Alternatives To Ejecting

Support

  • Troubleshooting

Fetching Data with AJAX Requests

React doesn't prescribe a specific approach to data fetching, but people commonly use either a library like axios or the fetch() API provided by the browser.

The global fetch function allows you to easily make AJAX requests. It takes in a URL as an input and returns a Promise that resolves to a Response object. You can find more information about fetch here.

A Promise represents the eventual result of an asynchronous operation, you can find more information about Promises here and here. Both axios and fetch() use Promises under the hood. You can also use the async / await syntax to reduce the callback nesting.

Make sure the fetch() API and Promises are available in your target audience's browsers. For example, support in Internet Explorer requires a polyfill.

You can learn more about making AJAX requests from React components in the FAQ entry on the React website.

← PreviousNext →
Create React App
Docs
Getting StartedDocumentation
Community
Stack OverflowSpectrumTwitter
More
GitHubStar
Facebook Open Source
Copyright © 2018 Facebook Inc.