Skip to content

Commit b208bd3

Browse files
authored
Document AJAX requests
1 parent 40c6fc1 commit b208bd3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

template/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ You can find the most recent version of this guide [here](https://github.com/fac
4141
- [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell)
4242
- [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env)
4343
- [Can I Use Decorators?](#can-i-use-decorators)
44+
- [Fetching Data with AJAX Requests](#fetching-data-with-ajax-requests)
4445
- [Integrating with an API Backend](#integrating-with-an-api-backend)
4546
- [Node](#node)
4647
- [Ruby on Rails](#ruby-on-rails)
@@ -988,6 +989,16 @@ Please refer to these two threads for reference:
988989

989990
Create React App will add decorator support when the specification advances to a stable stage.
990991

992+
## Fetching Data with AJAX Requests
993+
994+
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.
995+
996+
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).
997+
998+
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.
999+
1000+
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).
1001+
9911002
## Integrating with an API Backend
9921003

9931004
These tutorials will help you to integrate your app with an API backend running on another port,

0 commit comments

Comments
 (0)