{"id":10137,"date":"2024-04-22T06:55:28","date_gmt":"2024-04-22T06:55:28","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=10137"},"modified":"2024-04-22T06:55:28","modified_gmt":"2024-04-22T06:55:28","slug":"react-native-axios-request-on-ios-returns-network-error","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react-native\/react-native-axios-request-on-ios-returns-network-error","title":{"rendered":"React Native Axios Request on iOS Returns &#8220;Network Error&#8221;"},"content":{"rendered":"<p>The following code structure is implemented in App.js because the application needs to be completely initialized before making any API requests.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\">import React, { useState, useEffect } from 'react';\r\nimport { AppState, View } from 'react-native';\r\nimport Navigation from '.\/Navigation'; \/\/ Import your Navigation component\r\n\r\n\/**\r\n * Main application component.\r\n * Renders the navigation component based on the current app state.\r\n *\/\r\nconst App = () =&gt; {\r\n\/\/ State to hold the current app state\r\nconst [appState, setAppState] = useState(AppState.currentState);\r\n\r\nuseEffect(() =&gt; {\r\n\/\/ Function to handle changes in the app state.\r\n    \t\tconst handleAppStateChange = (nextAppState) =&gt; {\r\n                setAppState(nextAppState);\r\n            };\r\n\r\n\/\/ Subscribe to app state changes\r\nconst subscription = AppState.addEventListener('change',handleAppStateChange);\r\n\r\n\/\/ Unsubscribe when the component unmounts\r\nreturn () =&gt; {\r\nsubscription.remove();\r\n};\r\n}, []); \/\/ Empty dependency array to run effect only once\r\n\r\nreturn (\r\n&lt;View&gt;\r\n{\/* Render the navigation component only when app state is 'active' *\/}\r\n{appState === 'active' &amp;&amp; &lt;Navigation \/&gt;}\r\n    &lt;\/View&gt;\r\n);\r\n};\r\n\r\nexport default App;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following code structure is implemented in App.js because the application needs to be completely initialized before making any API requests. import React, { useState, useEffect } from &#8216;react&#8217;; import { AppState, View } from &#8216;react-native&#8217;; import Navigation from &#8216;.\/Navigation&#8217;; \/\/ Import your Navigation component \/** * Main application component. * Renders the navigation component [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-10137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-native"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10137"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=10137"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10137\/revisions"}],"predecessor-version":[{"id":10139,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10137\/revisions\/10139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/10138"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=10137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=10137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=10137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}