Ionic React Cheatsheet

See also: JavaScript React

Command Line

Input

const userInputRef = useRef<HTMLIonInputElement>(null);
const [message, setMessage] = useState<string>("");
const getUser = () => {
  const enteredUser = userInputRef.current!.value;
  if (!enteredUser) {  setMessage("Error"); }
}

Import

import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import ExploreContainer from '../components/ExploreContainer';
import HomePage from '../pages/Home';

State

const [userData, setUserData] = useState<any>({});
const [myNumber, setMyNumber] = useState<number>(0);
const [message, setMessage] = useState<string>("");