Electron Forge
  • Getting Started
  • Importing an Existing Project
  • CLI
  • Core Concepts
    • Why Electron Forge?
    • Build Lifecycle
  • Configuration
    • Configuration Overview
    • TypeScript Setup
    • Plugins
      • Webpack Plugin
      • Vite Plugin
      • Electronegativity Plugin
      • Auto Unpack Native Modules Plugin
      • Local Electron Plugin
      • Fuses Plugin
    • Makers
      • AppX
      • deb
      • DMG
      • Flatpak
      • pkg
      • RPM
      • Snapcraft
      • Squirrel.Windows
      • WiX MSI
      • ZIP
    • Publishers
      • Bitbucket
      • Electron Release Server
      • Google Cloud Storage
      • Nucleus
      • S3
      • Snapcraft
    • Hooks
  • Built-in Templates
    • Webpack
    • Webpack + Typescript
    • Vite
    • Vite + TypeScript
  • Guides
    • Code Signing
      • Signing a Windows app
      • Signing a macOS app
    • Custom App Icons
    • Framework Integration
      • React
      • React with TypeScript
      • Vue 3
    • Developing with WSL
  • Advanced
    • Auto Update
    • Debugging
    • Extending Electron Forge
      • Writing Plugins
      • Writing Templates
      • Writing Makers
      • Writing Publishers
    • API Docs
Powered by GitBook
On this page
  • Create the app and setup the Webpack config
  • Add the React dependencies
  • Integrate React code

Was this helpful?

Edit on
  1. Guides
  2. Framework Integration

React

How to create an Electron app with React and Electron Forge

PreviousFramework IntegrationNextReact with TypeScript

Last updated 1 year ago

Was this helpful?

Adding React support to the Webpack template doesn't require a complicated boilerplate to get started.

The following guide has been tested with React 18, Babel 7, and Webpack 5.

Create the app and setup the Webpack config

Create the app with the. Add the following packages to your devDependencies so that JSX and other React features can be used properly:

npm install --save-dev @babel/core @babel/preset-react babel-loader

Set up themodule with thein webpack.rules.js:

webpack.rules.js
module.exports = [
  // ... existing loader config ...
  {
    test: /\.jsx?$/,
    use: {
      loader: 'babel-loader',
      options: {
        exclude: /node_modules/,
        presets: ['@babel/preset-react']
      }
    }
  }
  // ... existing loader config ...
];

Add the React dependencies

Add the basic React packages to your dependencies:

npm install --save react react-dom

Integrate React code

You should now be able to start writing and using React components in your Electron app. The following is a very minimal example of how to start to add React code:

import * as React from 'react';
import { createRoot } from 'react-dom/client';

const root = createRoot(document.body);
root.render(<h2>Hello from React!</h2>);
// Add this to the end of the existing file
import './app.jsx';

For more about React, see their.

Webpack template
babel-loader
React preset
documentation