ISPEAKCODE.COM

TALK · REACT MEETUP #78 · 15 JUN 2024

Desktop apps with React components

Why desktop apps still matter, how we got from green-screen terminals to JavaScript everywhere, and how Electron and Next.js together (Nextron) turn React components into one app for macOS, Windows and Linux.

31 SLIDES ELECTRON + NEXT.JS TRY THE STARTER
Jump to the code
Nabil speaking into a microphone beside the projector screen, which reads 'Desktop apps are preferred for high-performance tasks', with the audience seated in front.
On stage · React Meetup #78
Wide view from the back of the room: rows of attendees facing the screen, with more people standing at the side.
A full house

THE MEETUP

React Meetup #78

When
Sat 15 Jun 2024
Group
ReactJS Bangalore
Talk
Unlocking cross-platform desktop apps with React components
01

REACT MEETUP #78

Unlocking cross-platform desktop apps with React components

02

PART 1

Why desktop apps?

03

Desktop apps still dominate in professional and enterprise environments.

04Two buttons meme: a sweating man can't choose between 'Desktop App' and 'Web App', captioned 'Building an enterprise application'.
05

50% of businesses still rely on desktop applications for critical operations.

06

Desktop apps are preferred for high-performance tasks.

07'The Most Interesting Man in the World' meme: 'I don't always build apps, but when I do, they're desktop apps.'
08

PART 2

How did we get here?

09

1980s–1990s

Early days

A green-on-black terminal window: 'Welcome to Qwontical. Enter your commands.' followed by a prompt.
10

1990s–2000s

Native development

The Microsoft Windows 3.0 start-up screen.
11

2000s

Cross-platform development

Comic meme: 'I promised my girlfriend that I'd learn her language.' 'Where's she from?' 'Java.'
12

2010s

Web technologies

Toy Story meme: Buzz shows Woody 'JavaScript, JavaScript everywhere'.
13

PART 3

Choosing desktop vs web apps

14

Accessibility and reach

WEB

Easy to reach from any device with an internet connection.

DESKTOP

Works offline, or where the connection is limited.

15Inhaling seagull meme, escalating from 'Ah! A web application' and '+ backend too' to 'Dockerized microservices architecture'.
16

Performance and resource intensity

DESKTOP

Resource-heavy work like video editing, 3D modelling or large-scale data processing, where you need direct access to the hardware.

17'Impossibru' meme: 'Native performance with a web app? Impossibru!'
18

User experience and interface

DESKTOP

A smoother user experience.

19Hipster meme: 'Web app? No thanks, I have Photoshop on my MacBook.'
20

PART 4

Building desktop apps using JavaScript

21
  • ELECTRONChromium and Node.js in one runtime: a single JavaScript codebase becomes a native window on macOS, Windows and Linux.
  • NEXT.JSThe React framework: pages, routing and static export for the screens inside that window.
22Morpheus meme: 'What if I told you you could combine both.'
23

⚡ Next.js + Electron = Nextron

24Baahubali meme: a baby labelled 'Nextron' held up high above the water.
25

PART 5

Let’s dive into some code

26

Start a Nextron app

The talk used --example basic-lang-typescript. Pick any of Nextron’s current examples and your package manager; the command updates as you go.

RUN WITH

then run the app in development mode

Examples listed from Nextron’s repository (v10.3). npm run dev starts Next.js and opens it in an Electron window; npm run build packages the app into dist/.

27

What you get

PROJECT LAYOUT
.
├── main                  // Electron: windows, menus, the OS
│   ├── main.ts
│   └── preload.ts        // the bridge into the page
├── renderer              // Next.js: your React components
│   ├── pages
│   │   ├── home.tsx
│   │   └── next.tsx
│   └── next.config.ts
├── resources             // app icons
├── electron-builder.yml  // packaging
└── package.json
28

One button, two processes

The starter’s home page has a Test IPC button. Press it here to follow the message from your React component to Electron’s main process and back. Simulated in your browser, using the starter template’s own code.

Home - Nextron (basic-lang-typescript)

⚡ Electron + Next.js ⚡

No message found

  1. RENDERER · pages/home.tsx
    window.ipc.send('message', 'Hello')
  2. PRELOAD · main/preload.ts
    ipcRenderer.send(channel, value)
  3. MAIN · main/main.ts
    ipcMain.on('message', async (event, arg) => {
      event.reply('message', `${arg} World!`)
    })
  4. RENDERER · pages/home.tsx
    window.ipc.on('message', (message) => {
      setMessage(message)
    })
29Success Kid meme: 'Built my first desktop app using Nextron.'
30

Questions?

31

Thank you