diff --git a/docs/next/network.html b/docs/next/network.html index e5bb284bbd0..4a550ee342d 100644 --- a/docs/next/network.html +++ b/docs/next/network.html @@ -92,31 +92,42 @@
The above examples show how you can make a request. In many cases, you will want to do something with the response.
Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:
-function getMoviesFromApiAsync() {
+function getMoviesFromApi() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
- .then((responseJson) => {
- return responseJson.movies;
+ .then((json) => {
+ return json.movies;
})
.catch((error) => {
console.error(error);
});
}
-You can also use the proposed ES2017 async/await syntax in a React Native app:
-async function getMoviesFromApi() {
+You can also use the async / await syntax in a React Native app:
+async function getMoviesFromApiAsync() {
try {
let response = await fetch(
'https://facebook.github.io/react-native/movies.json',
);
- let responseJson = await response.json();
- return responseJson.movies;
+ let json = await response.json();
+ return json.movies;
} catch (error) {
console.error(error);
}
}
Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.
+
+
+ -
+ Function Component Example
+
+ -
+ Class Component Example
+
+
+
+
+ >
+
+
By default, iOS will block any request that's not encrypted using SSL. If you need to fetch from a cleartext URL (one that begins with http) you will first need to add an App Transport Security exception. If you know ahead of time what domains you will need access to, it is more secure to add exceptions only for those domains; if the domains are not known until runtime you can disable ATS completely. Note however that from January 2017, Apple's App Store review will require reasonable justification for disabling ATS. See Apple's documentation for more information.
Using Other Networking Libraries
diff --git a/docs/next/network/index.html b/docs/next/network/index.html
index e5bb284bbd0..4a550ee342d 100644
--- a/docs/next/network/index.html
+++ b/docs/next/network/index.html
@@ -92,31 +92,42 @@
Handling the response
The above examples show how you can make a request. In many cases, you will want to do something with the response.
Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:
-function getMoviesFromApiAsync() {
+function getMoviesFromApi() {
return fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
- .then((responseJson) => {
- return responseJson.movies;
+ .then((json) => {
+ return json.movies;
})
.catch((error) => {
console.error(error);
});
}
-You can also use the proposed ES2017 async/await syntax in a React Native app:
-async function getMoviesFromApi() {
+You can also use the async / await syntax in a React Native app:
+async function getMoviesFromApiAsync() {
try {
let response = await fetch(
'https://facebook.github.io/react-native/movies.json',
);
- let responseJson = await response.json();
- return responseJson.movies;
+ let json = await response.json();
+ return json.movies;
} catch (error) {
console.error(error);
}
}
Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.
+
+
+ -
+ Function Component Example
+
+ -
+ Class Component Example
+
+
+
+
+ >
+
+
By default, iOS will block any request that's not encrypted using SSL. If you need to fetch from a cleartext URL (one that begins with http) you will first need to add an App Transport Security exception. If you know ahead of time what domains you will need access to, it is more secure to add exceptions only for those domains; if the domains are not known until runtime you can disable ATS completely. Note however that from January 2017, Apple's App Store review will require reasonable justification for disabling ATS. See Apple's documentation for more information.
Using Other Networking Libraries