{"id":1484,"date":"2023-09-25T09:25:44","date_gmt":"2023-09-25T08:25:44","guid":{"rendered":"https:\/\/codeflarelimited.com\/blog\/?p=1484"},"modified":"2023-09-25T09:25:47","modified_gmt":"2023-09-25T08:25:47","slug":"fetch-data-from-an-api-in-react-using-functional-components","status":"publish","type":"post","link":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/","title":{"rendered":"Fetch Data From an API in React Using Functional Components"},"content":{"rendered":"\n<p>In the context of frontend web development, a functional component is a fundamental building block in many modern JavaScript frameworks and libraries. It is a type of component used in frameworks like React and Vue.js, and it can also refer to a similar concept in other programming paradigms, like functional programming.<\/p>\n\n\n\n<p>In the context of React (which is one of the most popular JavaScript libraries that we are dealing), a functional component is a JavaScript function that returns JSX (JavaScript XML) to define the structure and appearance of a user interface element.<\/p>\n\n\n\n<p>You could choose to use either class or functional components in rendering your JSX. For this particular example, we have already demonstrated the &#8220;class&#8221; example using React Native. <a href=\"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-and-display-in-flatlist-in-react-native\/\">See this article<\/a><\/p>\n\n\n\n<p>In this tutorial, we are going to fetch data from an endpoint and display the results on our page using, of course, functional components as well as bootstrap for styling.<\/p>\n\n\n\n<p>We are going to be fetching data from this endpoint <a href=\"https:\/\/catfact.ninja\/breeds \">https:\/\/catfact.ninja\/breeds <\/a>. It&#8217;s a GET Request and requires no access token or authorization.<\/p>\n\n\n\n<p>The first thing we want to do is create a new react project and add our code. In our App.js or App.tsx, whichever one applies to you, we&#8217;re going to add the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import { useState, useEffect } from 'react';\n\nconst App = () =&gt; {\n return(\n &lt;div&gt;\n\n&lt;\/div&gt;\n}\n\nexport default App<\/code><\/pre>\n\n\n\n<p>Next, we want to have a function that fetches data from the given endpoint. We will create a function and call it <strong>fetchItems()<\/strong>.<\/p>\n\n\n\n<p>Let us fetch data from the endpoint in React JS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">const fetchItem = () =&gt; {\n      requestAnimationFrame(() =&gt;\n        fetch(`https:\/\/catfact.ninja\/breeds`, {\n          method: 'GET',\n        })\n          .then(response =&gt; response.json())\n          .then(responseJson =&gt; {\n            setData(responseJson.data)\n             console.warn(responseJson.data);\n          })\n          .catch(error =&gt; {\n            {\n              alert(error)\n            }\n          }),\n      );\n  }<\/code><\/pre>\n\n\n\n<p>Next, we need to show this data to see that at least we&#8217;re getting a response. So we will u<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"359\" src=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.00.54-PM.png\" alt=\"fetch data from an endpoint in react js\" class=\"wp-image-1485\" srcset=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.00.54-PM.png 496w, https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.00.54-PM-300x217.png 300w\" sizes=\"auto, (max-width: 496px) 100vw, 496px\" \/><\/figure>\n\n\n\n<p>Next, we need to render that data in a readable and presentable format. We will create a function called showData() and add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">  const showData = () => {\n    return data.map(item => {\n      return(\n        &lt;div class=\"col-sm-3\">\n        &lt;div class=\"card\" style={{width: \"18rem\"}}>\n        &lt;img src={image} class=\"card-img-top\" alt=\"...\" \/>\n        &lt;div class=\"card-body\">\n          &lt;p class=\"card-text\">Breed: {item.breed}.&lt;\/p>\n          &lt;p class=\"card-text\">Coat: {item.coat}.&lt;\/p>\n          &lt;p class=\"card-text\">Coat: {item.country}.&lt;\/p>\n          &lt;p class=\"card-text\">Origin: {item.origin}.&lt;\/p>\n          &lt;p class=\"card-text\">Patter: {item.pattern}.&lt;\/p>\n        &lt;\/div>\n      &lt;\/div>\n      &lt;\/div>\n      )\n    })\n  }<\/code><\/pre>\n\n\n\n<p>So, if you can see from the response, this endpoint does not really have an image for the various dog breeds, so I&#8217;m putting a placeholder dog image in the image section. Go ahead and use any placeholder image of your choice.<\/p>\n\n\n\n<p>Next, we want to render our main JSX in the return section as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">return(\n    &lt;div class=\"container\">\n    &lt;div class=\"row\">\n    {showData()}\n    &lt;\/div>\n    &lt;\/div>\n    )<\/code><\/pre>\n\n\n\n<p>Here&#8217;s the full working code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"jsx\" class=\"language-jsx\">import { useState, useEffect } from 'react';\nimport image from '.\/assets\/images\/happy.png';\nimport Nav from '.\/Nav'\n\nconst Home = () =>  {\n  const [data, setData] = useState([]);\n\n  useEffect(() => {\n    fetchItem()\n  },[])\n\n\n  const fetchItem = () => {\n      requestAnimationFrame(() =>\n        fetch(`https:\/\/catfact.ninja\/breeds`, {\n          method: 'GET',\n        })\n          .then(response => response.json())\n          .then(responseJson => {\n            setData(responseJson.data)\n             console.warn(responseJson.data);\n          })\n          .catch(error => {\n            {\n              alert(error)\n            }\n          }),\n      );\n  }\n\n  const showData = () => {\n    return data.map(item => {\n      return(\n        &lt;div class=\"col-sm-3\">\n        &lt;div class=\"card\" style={{width: \"18rem\"}}>\n        &lt;img src={image} class=\"card-img-top\" alt=\"...\" \/>\n        &lt;div class=\"card-body\">\n          &lt;p class=\"card-text\">Breed: {item.breed}.&lt;\/p>\n          &lt;p class=\"card-text\">Coat: {item.coat}.&lt;\/p>\n          &lt;p class=\"card-text\">Coat: {item.country}.&lt;\/p>\n          &lt;p class=\"card-text\">Origin: {item.origin}.&lt;\/p>\n          &lt;p class=\"card-text\">Patter: {item.pattern}.&lt;\/p>\n        &lt;\/div>\n      &lt;\/div>\n      &lt;\/div>\n      )\n    })\n  }\n\n    return(\n    &lt;div class=\"container\">\n    &lt;div class=\"row\">\n    {showData()}\n    &lt;\/div>\n    &lt;\/div>\n    )\n\n}\n\nexport default Home\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"582\" src=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.11.47-PM-1024x582.png\" alt=\"fetch data from an endpoint in react js\" class=\"wp-image-1486\" srcset=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.11.47-PM-1024x582.png 1024w, https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.11.47-PM-300x170.png 300w, https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.11.47-PM-768x436.png 768w, https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.11.47-PM.png 1440w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This is what our code looks like and this is how we fetch data from an api in react js. I hope it was helpful. Give me your feedback.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the context of frontend web development, a functional component is a fundamental building block in many modern<\/p>\n","protected":false},"author":1,"featured_media":1487,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[73,98],"tags":[],"class_list":["post-1484","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-js","category-softare-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Fetch Data From an API in React Using Functional Components<\/title>\n<meta name=\"description\" content=\"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fetch Data From an API in React Using Functional Components\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/codeflretech\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-25T08:25:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-25T08:25:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"917\" \/>\n\t<meta property=\"og:image:height\" content=\"477\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"codeflare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codeflaretech\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/\"},\"author\":{\"name\":\"codeflare\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/person\\\/7e65653d49add95629f8c1053c5cd76a\"},\"headline\":\"Fetch Data From an API in React Using Functional Components\",\"datePublished\":\"2023-09-25T08:25:44+00:00\",\"dateModified\":\"2023-09-25T08:25:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/\"},\"wordCount\":392,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Screen-Shot-2023-09-24-at-9.15.45-PM.png\",\"articleSection\":[\"react js\",\"softare development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/\",\"name\":\"Fetch Data From an API in React Using Functional Components\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Screen-Shot-2023-09-24-at-9.15.45-PM.png\",\"datePublished\":\"2023-09-25T08:25:44+00:00\",\"dateModified\":\"2023-09-25T08:25:47+00:00\",\"description\":\"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Screen-Shot-2023-09-24-at-9.15.45-PM.png\",\"contentUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/Screen-Shot-2023-09-24-at-9.15.45-PM.png\",\"width\":917,\"height\":477,\"caption\":\"fetch data from an endpoint in react functional component\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/fetch-data-from-an-api-in-react-using-functional-components\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"softare development\",\"item\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/softare-development\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Fetch Data From an API in React Using Functional Components\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\",\"name\":\"\",\"description\":\"Sustainable solutions\",\"publisher\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#organization\",\"name\":\"Codeflare Limited\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/codeflare.png\",\"contentUrl\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/codeflare.png\",\"width\":1040,\"height\":263,\"caption\":\"Codeflare Limited\"},\"image\":{\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/#\\\/schema\\\/person\\\/7e65653d49add95629f8c1053c5cd76a\",\"name\":\"codeflare\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g\",\"caption\":\"codeflare\"},\"description\":\"Latest tech news and coding tips.\",\"sameAs\":[\"https:\\\/\\\/codeflarelimited.com\\\/blog\",\"https:\\\/\\\/facebook.com\\\/codeflretech\",\"https:\\\/\\\/instagram.com\\\/codeflaretech\",\"https:\\\/\\\/x.com\\\/codeflaretech\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCuBLtiYqsajHdqw0uyt7Ofw?sub_confirmation=1\"],\"url\":\"https:\\\/\\\/codeflarelimited.com\\\/blog\\\/author\\\/watcher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fetch Data From an API in React Using Functional Components","description":"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/","og_locale":"en_US","og_type":"article","og_title":"Fetch Data From an API in React Using Functional Components","og_description":"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...","og_url":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/","article_author":"https:\/\/facebook.com\/codeflretech","article_published_time":"2023-09-25T08:25:44+00:00","article_modified_time":"2023-09-25T08:25:47+00:00","og_image":[{"width":917,"height":477,"url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","type":"image\/png"}],"author":"codeflare","twitter_card":"summary_large_image","twitter_creator":"@codeflaretech","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#article","isPartOf":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/"},"author":{"name":"codeflare","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/person\/7e65653d49add95629f8c1053c5cd76a"},"headline":"Fetch Data From an API in React Using Functional Components","datePublished":"2023-09-25T08:25:44+00:00","dateModified":"2023-09-25T08:25:47+00:00","mainEntityOfPage":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/"},"wordCount":392,"commentCount":0,"publisher":{"@id":"https:\/\/codeflarelimited.com\/blog\/#organization"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#primaryimage"},"thumbnailUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","articleSection":["react js","softare development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/","url":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/","name":"Fetch Data From an API in React Using Functional Components","isPartOf":{"@id":"https:\/\/codeflarelimited.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#primaryimage"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#primaryimage"},"thumbnailUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","datePublished":"2023-09-25T08:25:44+00:00","dateModified":"2023-09-25T08:25:47+00:00","description":"In this tutorial, we are going to fetch data from an api in react js and display the results on our page using, of course, functional ...","breadcrumb":{"@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#primaryimage","url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","contentUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","width":917,"height":477,"caption":"fetch data from an endpoint in react functional component"},{"@type":"BreadcrumbList","@id":"https:\/\/codeflarelimited.com\/blog\/fetch-data-from-an-api-in-react-using-functional-components\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codeflarelimited.com\/blog\/"},{"@type":"ListItem","position":2,"name":"softare development","item":"https:\/\/codeflarelimited.com\/blog\/softare-development\/"},{"@type":"ListItem","position":3,"name":"Fetch Data From an API in React Using Functional Components"}]},{"@type":"WebSite","@id":"https:\/\/codeflarelimited.com\/blog\/#website","url":"https:\/\/codeflarelimited.com\/blog\/","name":"","description":"Sustainable solutions","publisher":{"@id":"https:\/\/codeflarelimited.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeflarelimited.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codeflarelimited.com\/blog\/#organization","name":"Codeflare Limited","url":"https:\/\/codeflarelimited.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2020\/11\/codeflare.png","contentUrl":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2020\/11\/codeflare.png","width":1040,"height":263,"caption":"Codeflare Limited"},"image":{"@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/codeflarelimited.com\/blog\/#\/schema\/person\/7e65653d49add95629f8c1053c5cd76a","name":"codeflare","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/59cef917c86d965eea581d2747f51bd6382003a68bfce7c8a4dfec98b4cd838d?s=96&d=mm&r=g","caption":"codeflare"},"description":"Latest tech news and coding tips.","sameAs":["https:\/\/codeflarelimited.com\/blog","https:\/\/facebook.com\/codeflretech","https:\/\/instagram.com\/codeflaretech","https:\/\/x.com\/codeflaretech","https:\/\/www.youtube.com\/channel\/UCuBLtiYqsajHdqw0uyt7Ofw?sub_confirmation=1"],"url":"https:\/\/codeflarelimited.com\/blog\/author\/watcher\/"}]}},"jetpack_featured_media_url":"https:\/\/codeflarelimited.com\/blog\/wp-content\/uploads\/2023\/09\/Screen-Shot-2023-09-24-at-9.15.45-PM.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/1484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/comments?post=1484"}],"version-history":[{"count":2,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/1484\/revisions"}],"predecessor-version":[{"id":1489,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/posts\/1484\/revisions\/1489"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/media\/1487"}],"wp:attachment":[{"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/media?parent=1484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/categories?post=1484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeflarelimited.com\/blog\/wp-json\/wp\/v2\/tags?post=1484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}