React Ionic

Mobile Development with Ionic and React — Tabs, Toggles, and Toasts

Spread the love

If we know how to create React web apps but want to develop mobile apps, we can use the Ionic framework.

In this article, we’ll look at how to get started with mobile development with the Ionic framework with React.


We can add a tab bar with the IonTabBar and IonTabButton components.

For example, we can write:

import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import {
} from '@ionic/react';
import { IonReactRouter } from '@ionic/react-router';
import { triangle } from 'ionicons/icons';
import Tab1 from './pages/Tab1';

/* Core CSS required for Ionic components to work properly */
import '@ionic/react/css/core.css';

/* Basic CSS for apps built with Ionic */
import '@ionic/react/css/normalize.css';
import '@ionic/react/css/structure.css';
import '@ionic/react/css/typography.css';

const App: React.FC = () => (
          <Route path="/tab1" component={Tab1} exact={true} />
          <Route path="/" render={() => <Redirect to="/tab1" />} exact={true} />
        <IonTabBar slot="bottom">
          <IonTabButton tab="tab1" href="/tab1">
            <IonIcon icon={triangle} />
            <IonLabel>Tab 1</IonLabel>

export default App;

We add the components to the app.

And we can use the IonRouterOutlet to show the tab’s content.

The href has the path of the tab route to show.


We can add the IonToast component to add toasts into our app.

For example, we can write:

import React, { useState } from 'react';
import { IonButton, IonContent, IonToast } from '[@ionic/react]( "Twitter profile for @ionic/react")';
import './Tab1.css';

const Tab1: React.FC = () => {
  const [showToast, setShowToast] = useState(false);

  return (
      <IonButton onClick={() => setShowToast(true)} expand="block">Show Toast</IonButton>
        onDidDismiss={() => setShowToast(false)}
        message="Your settings have been saved."

export default Tab1;

We add the IonToast component to add the toast.

The isOpen prop sets when it’s open with a boolean.

onDidDismiss prop’s function is run when we dismiss the toast.

message has the toast message.

duration has the duration of the toast.


We can add toggles into our app by using the IonToggle component.

For example, we can write:

import React, { useState } from 'react';
import { IonContent, IonItem, IonItemDivider, IonLabel, IonList, IonToggle } from '@ionic/react';
import './Tab1.css';

const Tab1: React.FC = () => {
  const [checked, setChecked] = useState(false);

  return (
        <IonItemDivider>Default Toggle</IonItemDivider>
          <IonLabel>Checked: {JSON.stringify(checked)}</IonLabel>
          <IonToggle checked={checked} onIonChange={e => setChecked(e.detail.checked)} />
        <IonItemDivider>Disabled Toggle</IonItemDivider>
        <IonItem><IonToggle disabled /></IonItem>
        <IonItemDivider>Checked Toggle</IonItemDivider>
        <IonItem><IonToggle checked /></IonItem>
        <IonItemDivider>Toggle Colors</IonItemDivider>
        <IonItem><IonToggle color="primary" /></IonItem>
        <IonItem><IonToggle color="secondary" /></IonItem>
        <IonItem><IonToggle color="danger" /></IonItem>
        <IonItem><IonToggle color="light" /></IonItem>
        <IonItem><IonToggle color="dark" /></IonItem>
        <IonItemDivider>Toggles in a List</IonItemDivider>
          <IonToggle value="pepperoni" />
          <IonToggle value="sausage" disabled={true} />
          <IonToggle value="mushrooms" />

export default Tab1;

We add the Ionitem and add the IonToggle inside.

The IonItemDivider adds the headings for each section.

The color has the color of the toggle.


We can add toggles, toasts, and tabs with Ionic React.

Leave a Reply

Your email address will not be published. Required fields are marked *