Framework7 React Integration
Framework7 React is a wrapper library that integrates the Framework7 mobile UI framework with React, enabling developers to build full-featured iOS and Android applications. It provides React components that correspond to Framework7's extensive set of native-looking UI elements, abstracting away direct DOM manipulation and leveraging React's declarative paradigm. The library is currently stable at version 9.0.3 and maintains a frequent release cadence, with patch and minor updates often released weekly or bi-weekly, and major versions introducing significant UI overhauls, such as the new iOS 26 styles and updated Material You specifications in v9.0.0. Its key differentiators include a rich component library designed to mimic native mobile app aesthetics, seamless integration with Framework7's core APIs (like routing and modals), and strong support for hybrid app development workflows with tools like Cordova and Capacitor, making it a robust choice for PWA and hybrid mobile app projects.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'dialog')
cause Attempting to access `Framework7.instance` or its methods (e.g., `Framework7.instance.dialog`) before the Framework7 app is fully initialized.fixEnsure all calls to `Framework7.instance` or its APIs are placed within the `f7ready()` callback, or inside a `useEffect` hook that depends on `f7ready` having completed, guaranteeing the instance is available. -
Module not found: Can't resolve 'framework7-react' in '...' or 'Module not found: Can't resolve 'framework7/css/bundle''
cause The `framework7-react` package, its core `framework7` dependency, or the required CSS bundle is not installed or incorrectly referenced.fixRun `npm install framework7-react framework7 react react-dom` (or `yarn add`). Also, ensure you have `import 'framework7/css/bundle';` (or specific theme CSS) in your root React component or main entry file. -
Framework7 components must be used inside Framework7 App component.
cause A component provided by `framework7-react` (e.g., `f7Page`, `f7Navbar`) is being rendered outside of the main `<App>` component wrapper.fixEnsure that all Framework7 React components are direct or indirect children of the `<App>` component provided by `framework7-react` to ensure they have access to the Framework7 context.
Warnings
- breaking The `dynamicNavbar` functionality has been completely removed in v9.0.0. Components relying on this feature will break.
- breaking In v9.0.0, the default text for Navbar back links is now empty, favoring an icon-only approach.
- gotcha Version 9.0.0 introduces significant UI/UX changes for both iOS (new iOS 26 styles) and Material Design (updated Material You specs, new color schemes). Existing custom styles or themes might require adjustments.
Install
-
npm install framework7-react -
yarn add framework7-react -
pnpm add framework7-react
Imports
- App
const App = require('framework7-react').App;import { App } from 'framework7-react'; - Framework7
import Framework7 from 'framework7';
import { Framework7 } from 'framework7-react'; - f7ready
Framework7.instance.ready(() => {});import { f7ready } from 'framework7-react'; - f7Page, f7Navbar
import { Page, Navbar } from 'framework7-react';import { f7Page, f7Navbar } from 'framework7-react';
Quickstart
import React, { useEffect } from 'react';
import {
App,
View,
Page,
Navbar,
Block,
Button,
f7ready,
Framework7
} from 'framework7-react';
// Framework7 parameters
const f7params = {
name: 'My F7 React App',
theme: 'auto', // Detect iOS or MD theme automatically
routes: [
{
path: '/',
component: () => (
<Page>
<Navbar title="Hello F7 React" />
<Block strong>
<p>Welcome to a basic Framework7 React application!</p>
<p>This demonstrates a simple page with a functional button.</p>
<Button fill onClick={() => Framework7.instance?.dialog.alert('Button clicked!')}>
Click Me
</Button>
</Block>
</Page>
),
},
],
};
const MyApp: React.FC = () => {
useEffect(() => {
f7ready(() => {
console.log('Framework7 instance is ready and accessible via Framework7.instance');
// Example: Framework7.instance.router.navigate('/some-other-page');
});
}, []);
return (
<App {...f7params}>
{/* Main View for the app */}
<View main url="/" />
</App>
);
};
export default MyApp;
// To render, typically in index.tsx:
// import React from 'react';
// import { createRoot } from 'react-dom/client';
// import MyApp from './MyApp';
// import 'framework7/css/bundle'; // Crucial: Import Framework7 styles
//
// const rootElement = document.getElementById('root');
// if (rootElement) {
// createRoot(rootElement).render(<MyApp />);
// }