Expo Integration
This guide walks through integrating @dpage-ai/react-native-dpage into modern Expo (SDK 51+) applications.
Installation
Use expo install to automatically pin compatible versions:
expo install @dpage-ai/react-native-dpage
expo install @react-native-async-storage/async-storage react-native-safe-area-contextBasic Setup
1. Initialize the SDK
import { initDPage } from '@dpage-ai/react-native-dpage';
initDPage({
projectId: 'my-project',
apiToken: 'dpage_live_xxx',
});
export default function App() {
return <YourApp />;
}2. Use Dynamic Components
import { DynamicComponent } from '@dpage-ai/react-native-dpage';
function HomeScreen() {
return (
<View>
<DynamicComponent name="PromoBanner" />
<DynamicComponent
name="ProductList"
data={{ category: 'featured' }}
/>
</View>
);
}Expo Configuration
Store your credentials in app.json or app.config.js:
{
"expo": {
"extra": {
"dpage": {
"projectId": "acme-prod",
"apiToken": "dpage_live_XXXXXXXXXXXXXXXX"
}
}
}
}Then access in your code:
import Constants from 'expo-constants';
import { initDPage } from '@dpage-ai/react-native-dpage';
const { projectId, apiToken } = Constants.expoConfig?.extra?.dpage || {};
initDPage({
projectId,
apiToken,
});Environment-Specific Config
Use app.config.js for dynamic configuration:
export default ({ config }) => ({
...config,
extra: {
dpage: {
projectId: process.env.DPAGE_PROJECT_ID || 'demo',
apiToken: process.env.DPAGE_API_TOKEN || '',
},
},
});Working Across Expo Environments
Expo Go / Dev Client
Works out of the box. AsyncStorage and safe area context are bundled with Expo.
EAS Build / Production
Use the same install commands. No extra native configuration required.
Web
Fetch and AsyncStorage operations run in the browser. Ensure CORS is configured.
Expo Router Integration
Works seamlessly with Expo Router:
import { Slot } from 'expo-router';
import { initDPage, preloadComponents } from '@dpage-ai/react-native-dpage';
import { useEffect } from 'react';
initDPage({
projectId: 'my-project',
apiToken: 'dpage_live_xxx',
});
export default function RootLayout() {
useEffect(() => {
// Preload critical components
preloadComponents(['Header', 'Footer', 'BottomTabs']);
}, []);
return <Slot />;
}import { DynamicComponent } from '@dpage-ai/react-native-dpage';
export default function HomeScreen() {
return (
<ScrollView>
<DynamicComponent name="HomeHero" />
<DynamicComponent name="FeaturedProducts" />
</ScrollView>
);
}Development Tips
Preload on App Launch
Use preloadComponents in your root layout to warm up cache entries.
Match Your Design System
Use renderLoading and renderError props to match your app's design.
Use with Navigation
Combine with Expo Router or React Navigation as you would any other component.
Monitor with Events
Wire up event handlers for analytics, log cache hits, and monitor fallbacks.
EAS Build Configuration
For EAS builds, ensure environment variables are set:
{
"build": {
"production": {
"env": {
"DPAGE_PROJECT_ID": "my-production-project",
"DPAGE_API_TOKEN": "dpage_live_xxx"
}
},
"preview": {
"env": {
"DPAGE_PROJECT_ID": "my-staging-project",
"DPAGE_API_TOKEN": "dpage_staging_xxx"
}
}
}
}Troubleshooting
AbortController not defined
This occurs on older Expo SDK versions. Ensure you're on the latest Expo SDK. For custom web builds, include a polyfill.
Missing peer dependency warning
Re-run the installation command:
expo install @react-native-async-storage/async-storage react-native-safe-area-contextAPI requests blocked
Check your Expo dev server proxy settings or configure HTTPS/CORS on your backend. For web builds, ensure the API supports CORS.