ionic-react
Original:🇺🇸 English
Translated
Guides the agent through Ionic Framework development with React — project structure, React-specific Ionic components, IonReactRouter and navigation patterns, Ionic lifecycle hooks (useIonViewWillEnter, useIonViewDidEnter, useIonViewWillLeave, useIonViewDidLeave), state management integration, and React-specific best practices for Ionic apps. Do not use for plain Capacitor React apps without Ionic (use capacitor-react), Ionic with Angular or Vue, creating a new Ionic app (use ionic-app-creation), upgrading Ionic to a newer version (use ionic-app-upgrades), or general Ionic component usage without React-specific context (use ionic-app-development).
2installs
Sourcecapawesome-team/skills
Added on
NPX Install
npx skill4agent add capawesome-team/skills ionic-reactTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Ionic React
Develop Ionic Framework apps with React — project structure, IonReactRouter, React-specific components, lifecycle hooks, state management, and best practices.
Prerequisites
- Ionic Framework 7 or 8 with .
@ionic/react - React 18 or later.
- Node.js and npm installed.
- For iOS: Xcode installed.
- For Android: Android Studio installed.
Agent Behavior
- Auto-detect before asking. Check the project for dependencies (
package.json,@ionic/react,@ionic/react-router,react), platforms (@capacitor/core,android/), build tools, and TypeScript usage. Only ask the user when something cannot be detected.ios/ - Guide step-by-step. Walk the user through the process one step at a time. Never present multiple unrelated questions at once.
- Adapt to the project. Detect the existing code style (TypeScript vs. JavaScript, state management library, routing setup) and generate code that matches.
Procedures
Step 1: Analyze the Project
Auto-detect the following by reading project files:
- Ionic version: Read version from
@ionic/react.package.json - React version: Read version from
react.package.json - Capacitor version: Read version from
@capacitor/core(if present).package.json - TypeScript: Check if exists and if
tsconfig.jsonfiles are used..tsx - Router: Check if and
@ionic/react-routerare inreact-router-dom.package.json - State management: Check for
package.json,redux,@reduxjs/toolkit,zustand,jotai, or similar.@tanstack/react-query - Platforms: Check which directories exist (,
android/).ios/ - Build tool: Check for ,
vite.config.ts,angular.json, etc.webpack.config.js
Step 2: Project Structure
A standard Ionic React project follows this structure:
project-root/
├── android/ # Android native project (Capacitor)
├── ios/ # iOS native project (Capacitor)
├── public/
├── src/
│ ├── components/ # Reusable UI components
│ ├── hooks/ # Custom React hooks
│ ├── pages/ # Page components (one per route)
│ ├── services/ # Service modules for API and native calls
│ ├── context/ # React context providers
│ ├── theme/
│ │ └── variables.css # Ionic CSS custom properties
│ ├── App.tsx # Root component with IonReactRouter
│ └── main.tsx # Entry point with setupIonicReact()
├── capacitor.config.ts # Capacitor configuration
├── ionic.config.json # Ionic CLI configuration
├── package.json
├── tsconfig.json
└── vite.config.ts # Or other bundler configIf the project does not follow this structure, adapt all guidance to the project's actual directory layout. Do not restructure the project unless the user explicitly asks.
Step 3: App Initialization
The entry point must call before rendering the app. This function initializes the Ionic Framework for React.
setupIonicReact()Verify that (or ) contains:
src/main.tsxsrc/index.tsxtypescript
import { setupIonicReact } from '@ionic/react';
setupIonicReact();setupIonicReact()typescript
setupIonicReact({
mode: 'ios', // Force iOS mode on all platforms ('ios' | 'md')
rippleEffect: false, // Disable Material Design ripple effect
animated: true, // Enable/disable all animations
});If is missing or called after rendering, Ionic components will not function correctly.
setupIonicReact()Step 4: Routing and Navigation
Read for complete routing patterns including:
references/routing.md- setup
IonReactRouter - page management
IonRouterOutlet - Tab-based navigation with
IonTabs - Side menu navigation with
IonMenu - Programmatic navigation with
useIonRouter - Route guards and route parameters
Key principles:
- Use instead of React Router's
IonReactRouter. It is required for Ionic page transitions.BrowserRouter - Use to contain routes. It manages the page stack and transition animations.
IonRouterOutlet - Pass prop to
component— do not useRouteorrenderinsidechildren.IonRouterOutlet - Use for programmatic navigation — it provides Ionic-aware navigation with transition animations.
useIonRouter
Step 5: Ionic Lifecycle Hooks
Read for detailed lifecycle hook usage.
references/lifecycle.mdIonic React pages stay mounted in the DOM after navigation. Standard React only fires on initial mount, not on every page visit. Use Ionic lifecycle hooks for per-visit logic:
useEffect| Hook | Use for |
|---|---|
| Refresh data before the page becomes visible |
| Start animations or focus inputs after page is visible |
| Pause media, save draft state |
| Cleanup after page is fully hidden |
These hooks only work in components that:
- Are rendered as the of a
componentinsideRoute.IonRouterOutlet - Render as their root element.
IonPage
Step 6: React-Specific Ionic Hooks
Read for all available hooks and usage examples.
references/hooks.mdIonic React provides hooks for presenting overlays and controlling navigation without managing state manually:
| Hook | Purpose |
|---|---|
| Present alert dialogs |
| Show toast notifications |
| Present action sheets |
| Show/dismiss loading indicators |
| Present modals programmatically |
| Present popovers programmatically |
| Present picker dialogs |
| Navigate with Ionic animations |
Step 7: React-Specific Component Patterns
Read for detailed component patterns including:
references/components.md- Page structure with
IonPage - Inline overlays (modals, popovers) with binding
isOpen - Pull-to-refresh with
IonRefresher - Infinite scroll with
IonInfiniteScroll - Forms with Ionic input components
Key principles:
- Every page must render as root. This is required for transitions and lifecycle hooks.
IonPage - Use for text inputs and
onIonInputfor select, toggle, checkbox, and range components.onIonChange - Access values via (or
e.detail.valuefor toggles/checkboxes).e.detail.checked - Use inline overlays with for simpler state management, or use overlay hooks (
isOpen,useIonModal, etc.) for imperative usage.useIonAlert
Step 8: State Management
Read for patterns with React Context, Redux Toolkit, Zustand, and TanStack Query.
references/state-management.mdKey principles:
- Page caching affects state. Since Ionic keeps pages mounted, state persists across navigations. Use to refresh stale data.
useIonViewWillEnter - Place providers outside . Context providers, Redux
IonReactRouter, andProvidershould wrap the router so all pages have access.QueryClientProvider - Do not add a state library unless needed. For simple apps, React Context and /
useStateare sufficient.useReducer
Step 9: Build and Run
After implementing changes:
bash
npm run build
npx cap sync
npx cap run android
npx cap run iosFor development with live reload:
bash
ionic serveFor native development with live reload:
bash
ionic cap run android --livereload --external
ionic cap run ios --livereload --externalError Handling
- Ionic lifecycle hooks not firing: Verify that the component renders as its root element and is the
IonPageof acomponentinsideRoute. Lifecycle hooks do not fire in child components or components rendered viaIonRouterOutlet/renderprops.children - Page transitions not animating: Ensure is used instead of
IonReactRouter. Ensure routes use theBrowserRouterprop, notcomponentorrender. Verifychildrenis a direct child ofIonRouterOutletorIonReactRouter.IonTabs - Stale data after navigating back: Ionic keeps pages mounted in the DOM. Use to refresh data on every page visit instead of
useIonViewWillEnterwithuseEffect.[] - Tab bar disappears on sub-page: All routes (including detail routes) must be inside the within
IonRouterOutlet. Do not nest a separateIonTabsinside a tab page.IonRouterOutlet - errors or components not rendering: Ensure
setupIonicReactis called beforesetupIonicReact()orReactDOM.createRoot()in the entry file. Ensure all Ionic CSS files are imported (see Ionic CSS imports inReactDOM.render()orsrc/App.tsx).src/main.tsx - not appearing:
IonBackButtononly renders when there is navigation history. Set theIonBackButtonprop to provide a fallback route when the page is accessed directly.defaultHref - Form input values not updating: Use for
onIonInput/IonInput(notIonTextarea). UseonChangeforonIonChange,IonSelect,IonToggle,IonCheckbox. Access values viaIonRange.e.detail.value - Modal or popover content not styled: Ensure the overlay content is wrapped in . For modals, include
IonContentwithIonHeaderif a toolbar is needed.IonToolbar - React strict mode double-mounting: In development, React 18 strict mode mounts components twice. This can cause duplicate Ionic event listeners. Ensure cleanup functions properly remove listeners.
- returns undefined: The hook must be used inside a component that is a descendant of
useIonRouter. Verify the component tree includesIonReactRouteras an ancestor.IonReactRouter - CSS custom properties not applying: Ensure Ionic CSS files are imported in the correct order in or
src/App.tsx. The themesrc/main.tsxfile must be imported after the core Ionic CSS.variables.css
Related Skills
- — General Ionic development covering components, theming, and CLI usage.
ionic-app-development - — Create a new Ionic app from scratch.
ionic-app-creation - — Capacitor-specific React patterns for accessing native device features (without Ionic Framework).
capacitor-react - — Upgrade Ionic Framework to a newer version.
ionic-app-upgrades - — Install, configure, and use Capacitor plugins from official and community sources.
capacitor-plugins