React Counter Example - Ionic Typing CST Test
Loading…
React Counter Example — Ionic Code
Demonstrates a simple counter layout using Ionic React components and React for interactivity.
import React, { useState } from 'react';
import { IonApp, IonContent, IonButton, IonHeader, IonTitle, IonToolbar, IonText } from '@ionic/react';
const Counter = () => {
const [count, setCount] = useState(0);
const [isDark, setIsDark] = useState(false);
const toggleTheme = () => {
setIsDark(!isDark);
document.body.className = isDark ? 'light-theme' : 'dark-theme';
};
return (
<IonApp>
<IonHeader>
<IonToolbar>
<IonTitle>Ionic Counter</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent className="ion-padding" style={{ textAlign: 'center' }}>
<IonText><h2>Counter: {count}</h2></IonText>
<IonButton color="primary" onClick={() => setCount(count + 1)}>+</IonButton>
<IonButton color="danger" onClick={() => setCount(count - 1)}>-</IonButton>
<IonButton color="medium" onClick={() => setCount(0)}>Reset</IonButton>
<br /><br />
<IonButton color="tertiary" onClick={toggleTheme}>Switch Theme</IonButton>
</IonContent>
</IonApp>
);
};
export default Counter;Ionic Language Guide
Ionic Framework is an open-source UI toolkit for building high-quality, cross-platform mobile, desktop, and web apps using web technologies like HTML, CSS, and JavaScript, often paired with Angular, React, or Vue.
Primary Use Cases
- ▸Cross-platform mobile apps (iOS, Android)
- ▸Progressive Web Apps (PWA)
- ▸Desktop apps via Electron
- ▸Single Page Applications (SPA)
- ▸Rapid prototyping of mobile-first interfaces
Notable Features
- ▸Prebuilt mobile-optimized UI components
- ▸Cross-platform support for Web, Mobile, and Desktop
- ▸Integration with Angular, React, and Vue
- ▸Theming with CSS variables and Ionic theming
- ▸CLI tooling for scaffolding, building, and deploying apps
Origin & Creator
Created by Max Lynch, Ben Sperry, and Adam Bradley of Drifty Co. in 2013 to simplify hybrid mobile app development.
Industrial Note
Ionic is widely used in enterprise mobile apps, PWAs, and hybrid apps that need native-like performance across multiple platforms.