/capacitor-frameworks:capacitor-reactfrom capacitor-frameworks
Guides Capacitor app development with React — project structure, hooks for native features, state management, and React-specific best practices for accessing device APIs.
Ships in capacitor-frameworks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Develop Capacitor apps with React — project structure, hooks, state management, and React-specific patterns for accessing native device features.
package.json dependencies (react, react-dom, @capacitor/core), platforms (android/, ios/), build tools (vite.config.ts, next.config.js, next.config.ts, react-router.config.ts, webpack.config.js), and TypeScript usage. Only ask the user when something cannot be detected.Auto-detect the following by reading project files:
Framework variant: Examine package.json dependencies and config files to find the variant. Capacitor needs static web files with an index.html, so a framework with server rendering must be set to a static or client-only build:
| Variant | How to detect | Web directory (webDir) | Note |
|---|---|---|---|
| Vite | vite.config.ts or vite.config.js | dist | The capacitor-app-creation skill creates new React apps with Vite. |
| Next.js | next.config.js, next.config.mjs or next.config.ts | out | Needs output: 'export' in the Next.js config. Server features do not work in a Capacitor app. |
| React Router framework mode (the successor of Remix) | react-router.config.ts | build/client | Needs ssr: false in react-router.config.ts. |
| Create React App | react-scripts in package.json | build | Create React App is deprecated for new apps since February 2025. Do not start new projects with it. |
Compare the web directory with webDir in the Capacitor config file. If the project does not meet the note of its variant, tell the user before changing the configuration.
Capacitor version: Read @capacitor/core version from package.json.
React version: Read react version from package.json.
TypeScript: Check if tsconfig.json exists and if .tsx files are used.
Platforms: Check which directories exist (android/, ios/).
Capacitor config format: Check if the project uses capacitor.config.ts or capacitor.config.json.
State management: Check package.json for redux, @reduxjs/toolkit, zustand, jotai, @tanstack/react-query, or similar.
Router: Check package.json for react-router (version 7 and later), react-router-dom (version 6 and earlier), @tanstack/react-router, or similar.
A standard Capacitor React project follows this structure:
project-root/
├── android/ # Android native project (generated by Capacitor)
├── ios/ # iOS native project (generated by Capacitor)
├── public/
├── src/
│ ├── components/ # Reusable UI components
│ ├── hooks/ # Custom React hooks (including native feature hooks)
│ ├── pages/ # Page/route components
│ ├── services/ # Service modules for Capacitor plugin calls
│ ├── App.tsx # Root component
│ └── main.tsx # Entry point
├── capacitor.config.ts # Capacitor configuration
├── package.json
├── tsconfig.json
└── vite.config.ts # Or other bundler config
If 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.
Read references/plugin-usage-patterns.md for detailed patterns on how to use Capacitor plugins in React components and hooks.
Key principles:
useEffect for listeners — register and clean up Capacitor event listeners inside useEffect.Capacitor.isNativePlatform() or Capacitor.getPlatform() to guard platform-specific calls.@capacitor/* plugin in the major version of @capacitor/core of the project, for example npm install @capacitor/network@8 in a Capacitor 8 project. Do not use the latest tag and do not leave the version out. Both can install a plugin for a newer Capacitor major version. Then run npx cap sync.Read references/custom-hooks.md for reusable custom hook patterns that wrap Capacitor plugins.
Custom hooks encapsulate native feature access and provide a React-idiomatic API. When the user needs to access a native feature from multiple components, create a custom hook in src/hooks/ (or wherever the project keeps hooks).
When the project uses a state management library, integrate native data as follows:
useState/useReducer to share native data across components.Do not recommend adding a state management library unless the user's requirements justify it.
If the project uses React Router or another router:
The examples import from react-router. This is the package of React Router 7 and later. In a project with React Router 6 or earlier, import the same hooks from react-router-dom.
appUrlOpen events from the @capacitor/app plugin inside a useEffect in the root component or a dedicated hook. Navigate programmatically using the router's useNavigate() hook.import { useEffect } from 'react';
import { useNavigate } from 'react-router';
import { App } from '@capacitor/app';
import type { URLOpenListenerEvent } from '@capacitor/app';
const useDeepLinks = () => {
const navigate = useNavigate();
useEffect(() => {
const listener = App.addListener('appUrlOpen', (event: URLOpenListenerEvent) => {
const path = new URL(event.url).pathname;
navigate(path);
});
return () => {
listener.then(handle => handle.remove());
};
}, [navigate]);
};
backButton event from the @capacitor/app plugin to handle Android hardware back button presses.import { useEffect } from 'react';
import { useNavigate, useLocation } from 'react-router';
import { App } from '@capacitor/app';
const useBackButton = () => {
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
const listener = App.addListener('backButton', ({ canGoBack }) => {
if (canGoBack) {
navigate(-1);
} else {
App.exitApp();
}
});
return () => {
listener.then(handle => handle.remove());
};
}, [navigate, location]);
};
Use Capacitor.getPlatform() or Capacitor.isNativePlatform() to conditionally render components or apply platform-specific behavior:
import { Capacitor } from '@capacitor/core';
const MyComponent: React.FC = () => {
const platform = Capacitor.getPlatform(); // 'ios' | 'android' | 'web'
const isNative = Capacitor.isNativePlatform();
return (
<div>
{platform === 'ios' && <IOSSpecificComponent />}
{platform === 'android' && <AndroidSpecificComponent />}
{!isNative && <WebFallbackComponent />}
</div>
);
};
For reusable platform checks, create a utility or hook:
import { Capacitor } from '@capacitor/core';
export const usePlatform = () => {
return {
platform: Capacitor.getPlatform(),
isNative: Capacitor.isNativePlatform(),
isIOS: Capacitor.getPlatform() === 'ios',
isAndroid: Capacitor.getPlatform() === 'android',
isWeb: Capacitor.getPlatform() === 'web',
};
};
Use the @capacitor/app plugin to respond to app lifecycle events in React:
import { useEffect } from 'react';
import { App } from '@capacitor/app';
const useAppState = (onResume?: () => void, onPause?: () => void) => {
useEffect(() => {
const resumeListener = App.addListener('resume', () => {
onResume?.();
});
const pauseListener = App.addListener('pause', () => {
onPause?.();
});
return () => {
resumeListener.then(handle => handle.remove());
pauseListener.then(handle => handle.remove());
};
}, [onResume, onPause]);
};
Use this to refresh data when the app returns to the foreground, pause media, or save state when the app is backgrounded.
After implementing changes, build and sync:
npm run build
npx cap sync
To run on a device or emulator, list the targets first and pass one ID. Without --target the CLI asks for a device in the terminal when more than one is available:
npx cap run android --list
npx cap run android --target <android-target-id>
npx cap run ios --list
npx cap run ios --target <ios-target-id>
The Capacitor CLI does not start the dev server. Start it first and make it reachable from the network. The command keeps running, so start it in a second terminal or as a background process. For Vite:
npm run dev -- --host
Vite prints the network URL of the dev server (the default port is 5173). The device must be in the same network as the computer. Then run the app with the host and the port of this URL:
npx cap run android --live-reload --host <ip-address> --port 5173 --target <android-target-id>
npx cap run ios --live-reload --host <ip-address> --port 5173 --target <ios-target-id>
The options --livereload and --external belong to the Ionic CLI (ionic cap run). The Capacitor CLI does not have them.
npx cap sync was run after installing a plugin. Verify the plugin is listed in package.json dependencies.Capacitor is not defined: The @capacitor/core package must be installed. Install it in the major version of the other @capacitor/* packages in package.json, for example npm install @capacitor/core@8 in a Capacitor 8 project. Do not use the latest tag and do not leave the version out. Both can install a newer major version than this skill covers.Capacitor.isNativePlatform(). Many plugins have web implementations, but some (e.g., @capacitor/camera with native UI) only work on iOS/Android.useEffect that calls remove() on the listener handle. Failing to do so causes duplicate listeners on re-renders.useRef to hold the latest value, or add the state variable to the useEffect dependency array and re-register the listener. With React 19.2 or later, the hook useEffectEvent is made for this case: wrap the handler in useEffectEvent and call it from the listener. The handler then always sees the latest state and the listener is not registered again.--host, and that the host passed to npx cap run is the network address of the dev server, not localhost. Verify no firewall is blocking the dev server port.npx cap run fails with an unknown option --livereload or --external: These are options of the Ionic CLI. Use the commands in the Live Reload section of Step 9.window.localStorage, navigator.geolocation) used without Capacitor alternatives. Use Capacitor plugins (@capacitor/preferences, @capacitor/geolocation) instead.Camera.takePhoto is not a function: The installed @capacitor/camera is older than 8.1.0. In a Capacitor 8 project, update the plugin with npm install @capacitor/camera@8 and run npx cap sync. In a Capacitor 6 or 7 project, use Camera.getPhoto().ionic-react — Ionic Framework-specific React patterns (IonReactRouter, lifecycle hooks, overlay hooks) for apps using @ionic/react.capacitor-app-creation: Create a new Capacitor app from scratch.capacitor-angular — Angular-specific patterns and best practices for Capacitor app development.capacitor-vue: Vue-specific patterns and best practices for Capacitor app development.capacitor-app-upgrades — Upgrade a Capacitor app to a newer major version.capacitor-plugins — Install, configure, and use Capacitor plugins from official and community sources.capacitor-push-notifications — Set up push notifications with Firebase Cloud Messaging in a Capacitor app.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub capawesome-team/skills --plugin capacitor-frameworks3 skills in this plugin
/capacitor-angularGuides the agent through Angular-specific patterns for Capacitor app development. Covers project structure, adding Capacitor to Angular projects, using Capacitor plugins in Angular services and components, change detection for plugin event listeners with signals in zoneless and zone-based apps (NgZone integration), lifecycle hook patterns, dependency injection, routing with deep links, live reload, and platform detection. Do not use for creating a new Capacitor app from scratch, upgrading Capacitor versions, installing specific plugins, Ionic Framework setup, or non-Angular frameworks./capacitor-vueGuides the agent through Vue-specific patterns for Capacitor app development. Covers Vue 3 Composition API with Capacitor plugins, custom composables for native features, reactive plugin state, lifecycle hook patterns, Vue Router deep link integration, platform detection, PWA Elements setup, Quasar Framework integration, and Nuxt integration. Do not use for creating a new Capacitor app from scratch, upgrading Capacitor versions, installing specific plugins, Ionic Framework with Vue setup, or non-Vue frameworks.Other plugins' skills for the same job