Can I share code between a web app and a mobile app?
Approaches to code sharing
React Native with React Native Web allows you to share components between web and mobile, but you may need platform-specific adjustments. Flutter can compile to web, but the UI may not feel native on the web.
Alternatively, you can share only business logic (e.g., in JavaScript/TypeScript or Dart) and write separate UIs for each platform. This is often more practical for complex apps.
- React Native + React Native Web: share components
- Flutter: share logic and some UI via Flutter Web
- Kotlin Multiplatform: share logic between mobile and web (via Kotlin/JS)
- Separate UI layers for best user experience
What to share
Business logic, data models, API clients, and state management are good candidates for sharing. UI code is harder to share because web and mobile have different interaction patterns and design guidelines.
For example, you can share a Redux store or a repository layer between React and React Native. In Flutter, you can share Dart code between mobile and web, but you might need to adapt the UI.
Common mistakes
- Expecting to share 100% of code; usually only a portion is shareable.
- Using a web framework for mobile and getting a non-native feel.
- Ignoring platform-specific UX guidelines when sharing UI.
