PageSourceSearch

https://create-react-app.dev/assets/js/14d1cfa4.950809b3.js

js create-react-app.dev collected 2026-09-24 07:30:43 UTC 6,171 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkcra_docs=self.webpackChunkcra_docs||[]).push([[9839],{876:function(e,t,r){r.d(t,{Zo:function(){return l},kt:function(){return h}});var a=r(2784);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function c(e,t){if(null==e)return{};var r,a,n=function(e,t){if(null==e)return{};var r,a,n={},o=Object.keys(e);for(a=0;a<o.length;a++)r=o[a],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)r=o[a],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var s=a.createContext({}),p=function(e){var t=a.useContext(s),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},l=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},d=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,s=e.parentName,l=c(e,["components","mdxType","originalType","parentName"]),d=p(r),h=n,f=d["".concat(s,".").concat(h)]||d[h]||u[h]||o;return r?a.createElement(f,i(i({ref:t},l),{},{components:r})):a.createElement(f,i({ref:t},l))}));function h(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,i=new Array(o);i[0]=d;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c.mdxType="string"==typeof e?e:n,i[1]=c;for(var p=2;p<o;p++)i[p]=r[p];return a.createElement.apply(null,i)}return a.createElement.apply(null,r)}d.displayName="MDXCreateElement"},8295:function(e,t,r){r.r(t),r.d(t,{frontMatter:function(){return c},contentTitle:function(){return s},metadata:function(){return p},toc:function(){return l},default:function(){return d}});var a=r(7896),n=r(1461),o=(r(2784),r(876)),i=["components"],c={id:"fetching-data-with-ajax-requests",title:"Fetching Data with AJAX Requests",sidebar_label:"Fetching Data"},s=void 0,p={unversionedId:"fetching-data-with-ajax-requests",id:"fetching-data-with-ajax-requests",title:"Fetching Data with AJAX Requests",description:"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.",source:"@site/../docs/fetching-data-with-ajax-requests.md",sourceDirName:".",slug:"/fetching-data-with-ajax-requests",permalink:"/docs/fetching-data-with-ajax-requests",editUrl:"https://github.com/facebook/create-react-app/edit/main/docusaurus/website/../docs/fetching-data-with-ajax-requests.md",tags:[],version:"current",lastUpdatedBy:"Dan Abramov",lastUpdatedAt:1625672679,formattedLastUpdatedAt:"7/7/2021",frontMatter:{id:"fetching-data-with-ajax-requests",title:"Fetching Data with AJAX Requests",sidebar_label:"Fetching Data"},sidebar:"docs",previous:{title:"Proxying in Development",permalink:"/docs/proxying-api-requests-in-development"},next:{title:"Integrating with an API",permalink:"/docs/integrating-with-an-api-backend"}},l=[],u={toc:l};function d(e){var t=e.components,r=(0,n.Z)(e,i);return(0,o.kt)("wrapper",(0,a.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"React doesn't prescribe a specific approach to data fetching, but people commonly use either a library like ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/axios/axios"},"axios")," or the ",(0,o.kt)("a",{parentName:"p",href:"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"},(0,o.kt)("inlineCode",{parentName:"a"},"fetch()")," API")," provided by the browser."),(0,o.kt)("p",null,"The global ",(0,o.kt)("inlineCode",{parentName:"p"},"fetch")," function allows you to make AJAX requests. It takes in a URL as an input and returns a ",(0,o.kt)("inlineCode",{parentName:"p"},"Promise")," that resolves to a ",(0,o.kt)("inlineCode",{parentName:"p"},"Response")," object. You can find more information about ",(0,o.kt)("inlineCode",{parentName:"p"},"fetch")," ",(0,o.kt)("a",{parentName:"p",href:"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"},"here"),"."),(0,o.kt)("p",null,"A Promise represents the eventual result of an asynchronous operation, you can find more information about Promises ",(0,o.kt)("a",{parentName:"p",href:"https://www.promisejs.org/"},"here")," and ",(0,o.kt)("a",{parentName:"p",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"},"here"),". Both axios and ",(0,o.kt)("inlineCode",{parentName:"p"},"fetch()")," use Promises under the hood. You can also use the ",(0,o.kt)("a",{parentName:"p",href:"https://davidwalsh.name/async-await"},(0,o.kt)("inlineCode",{parentName:"a"},"async / await"))," syntax to reduce the callback nesting."),(0,o.kt)("p",null,"Make sure the ",(0,o.kt)("a",{parentName:"p",href:"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"},(0,o.kt)("inlineCode",{parentName:"a"},"fetch()")," API")," and ",(0,o.kt)("a",{parentName:"p",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"},"Promises")," are available in your target audience's browsers.\nFor example, support in Internet Explorer requires a ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/facebook/create-react-app/blob/main/packages/react-app-polyfill/README.md"},"polyfill"),"."),(0,o.kt)("p",null,"You can learn more about making AJAX requests from React components in ",(0,o.kt)("a",{parentName:"p",href:"https://reactjs.org/docs/faq-ajax.html"},"the FAQ entry on the React website"),"."))}d.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.