npx skills add ...
npx skills add expo/skills --skill use-dom
Use Expo DOM components to run web code in a webview on native and as-is on web. Migrate web code to native incrementally.
npx skills add expo/skills --skill use-dom
DOM components allow web code to run verbatim in a webview on native platforms while rendering as-is on web. This enables using web-only libraries like recharts, react-syntax-highlighter, or any React web library in your Expo app without modification.
Use DOM components when you need:
Avoid DOM components when:
_layout files cannot be DOM componentsCreate a new file with the 'use dom'; directive at the top:
'use dom'; directive at the top of the filedom PropEvery DOM component receives a special dom prop for webview configuration. Always type it in your props:
dom Prop OptionsPass async functions as props to expose native functionality to the DOM component:
DOM components can use any web library:
CSS imports must be in the DOM component file since they run in isolated context:
Or use inline styles / CSS-in-JS:
The expo-router <Link /> component and router API work inside DOM components:
These hooks don't work directly in DOM components because they need synchronous access to native routing state:
useLocalSearchParams()useGlobalSearchParams()usePathname()useSegments()useRootNavigation()useRootNavigationState()Solution: Read these values in the native parent and pass as props:
Check if code is running in a DOM component:
Prefer requiring assets instead of using the public directory:
Import and use DOM components like regular components:
| Platform | Behavior |
|---|---|
| iOS | Rendered in WKWebView |
| Android | Rendered in WebView |
| Web | Rendered as-is (no webview wrapper) |
On web, the dom prop is ignored since no webview is needed.