mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-05-15 17:47:41 +08:00
Move fetching data with ajax requests to its own file
This commit is contained in:
15
docusaurus/docs/fetching-data-with-ajax-requests.md
Normal file
15
docusaurus/docs/fetching-data-with-ajax-requests.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
id: fetching-data-with-ajax-requests
|
||||
title: 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.
|
||||
|
||||
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](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).
|
||||
|
||||
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.
|
||||
|
||||
Make sure the [`fetch()` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) are available in your target audience's browsers.
|
||||
For example, support in Internet Explorer requires a [polyfill](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md).
|
||||
|
||||
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).
|
||||
@@ -11,7 +11,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [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)
|
||||
@@ -26,19 +25,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
|
||||
- [Advanced Configuration](#advanced-configuration)
|
||||
- [Alternatives to Ejecting](#alternatives-to-ejecting)
|
||||
|
||||
## 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.
|
||||
|
||||
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](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).
|
||||
|
||||
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.
|
||||
|
||||
Make sure the [`fetch()` API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) are available in your target audience's browsers.
|
||||
For example, support in Internet Explorer requires a [polyfill](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md).
|
||||
|
||||
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,
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
"adding-flow",
|
||||
"adding-relay",
|
||||
"adding-a-router",
|
||||
"adding-custom-environment-variables"
|
||||
"adding-custom-environment-variables",
|
||||
"fetching-data-with-ajax-requests"
|
||||
],
|
||||
"Testing": ["running-tests", "debugging-tests"],
|
||||
"Deployment": ["publishing-components-to-npm", "deployment"],
|
||||
|
||||
Reference in New Issue
Block a user