Ionic React – Getting started (Javascript)

The Ionic framework team has announced React is officially supported in Ionic.
Let’s build an app for web and devices.

This project uses Javascript, you can also use the Typescript version

On the command line, let’s run:

npx create-react-app yourAppName
then
cd yourAppName
then
npm start

App runs in the browser

Let’s install with npm (and save to package.json) ionic/react and capacitor

npm i -S @ionic/core @ionic/react @capacitor/cli @capacitor/core

Optional: Axios, Redux, React-Router, React-Dropzone
npm i -S axios react-dropzone react-redux react-router react-router-dom redux redux-devtools

Next step: build and run on a device

First run npm run build to create the build folder which will be used by the ionic capacitor to generate the android app

Create a ionic.config.json file with the following content

{
"name": "ionic react app",
"integrations": {
"capacitor": {}
},
"type": "custom"
}

And a capacitor.config.json file

{
"appId": "com.yourdomain.yourappname",
"appName": "ionic react app",
"bundledWebRuntime": false,
"webDir": "build"
}

Run the ionic capacitor from the command line
ionic capacitor add android

Now launch Android Studio with npx cap open android

App running on the device

Add in package.json, section “scripts”:
"ionic:build": "npm run build && ionic capacitor copy"

Then run ionic capacitor run android

Same process applies to deploy to ios on a mac, just change the commands with ios instead of android

One comment

Comments are closed.