Networking & Deployment
Fetching data
import { useEffect, useState } from 'react';
function Users() {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch('https://api.example.com/users')
.then((res) => res.json())
.then(setUsers)
.catch(console.error);
}, []);
return /* render users */;
}
Using async/await
async function loadUsers() {
try {
const res = await fetch('https://api.example.com/users');
return await res.json();
} catch (e) {
console.error('Failed', e);
}
}
Building for the stores
Expo’s EAS Build creates installable apps in the cloud:
npm install -g eas-cli
eas build --platform android
eas build --platform ios
Tip: Store secrets and the API base URL in environment config, never hard-coded in components.