mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
Document AJAX requests
This commit is contained in:
@@ -41,6 +41,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
|
||||
- [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell)
|
||||
- [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env)
|
||||
- [Can I Use Decorators?](#can-i-use-decorators)
|
||||
- [Fetching Data with AJAX Requests](#fetching-data-with-ajax-requests)
|
||||
- [Integrating with an API Backend](#integrating-with-an-api-backend)
|
||||
- [Node](#node)
|
||||
- [Ruby on Rails](#ruby-on-rails)
|
||||
@@ -988,6 +989,16 @@ Please refer to these two threads for reference:
|
||||
|
||||
Create React App will add decorator support when the specification advances to a stable stage.
|
||||
|
||||
## Fetching Data with AJAX Requests
|
||||
|
||||
React doesn't prescribe a specific approach to data fetching, but people commonly use either a library like [axios](https://github.com/axios/axios) or the [`fetch()` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) provided by the browser. Conveniently, Create React App includes a polyfill for `fetch()` so you can use it without worrying about the browser support.
|
||||
|
||||
The global `fetch` function allows to easily makes 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](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).
|
||||
|
||||
This project also includes a [Promise polyfill](https://github.com/then/promise) which provides a full implementation of Promises/A+. A Promise represents the eventual result of an asynchronous operation, you can find more information about Promises [here](https://www.promisejs.org/) and [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). Both axios and `fetch()` use Promises under the hood. You can also use the [`async / await`](https://davidwalsh.name/async-await) syntax to reduce the callback nesting.
|
||||
|
||||
You can learn more about making AJAX requests from React components in [the FAQ entry on the React website](https://reactjs.org/docs/faq-ajax.html).
|
||||
|
||||
## Integrating with an API Backend
|
||||
|
||||
These tutorials will help you to integrate your app with an API backend running on another port,
|
||||
|
||||
Reference in New Issue
Block a user