Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

State Management Acr | Electron.js Desktop App Development l | BraveProgrammer
  1. Courses
  2. /
  3. Electron.js Desktop App Development

Lesson 10 of 28

·javascript

State Management Across Processes

10 mins

Course progress36%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Avoid keeping duplicate copies of state in multiple renderers – use a **single source of truth** in the main process.
  • `ipcRenderer.invoke` is perfect for *get* operations, while `send` works for *set* without waiting for a response.
  • Libraries like **electron-store** simplify persistence (JSON file in userData).
  • Emit change events (`store:changed`) so UI updates automatically.

State Management Across Processes

Because the UI lives in a separate renderer, you need a strategy to keep data in sync.

Option 1: Central store in the Main process

  • Store app‑wide state in a plain JavaScript object.
  • Expose getState / setState via the preload bridge.
  • Emit change events to renderers when the state updates.
// preload/bridge.js
contextBridge.exposeInMainWorld('store', {
  get: () => ipcRenderer.invoke('store:get'),
  set: (key, value) => ipcRenderer.send('store:set', key, value),
  onChange: (cb) => ipcRenderer.on('store:changed', (e, newState) => cb(newState))
});

Option 2: Use a lightweight library (e.g., Redux, MobX) inside the renderer only, and persist to disk via IPC when needed.

Option 3: electron-store – a ready‑made persistent store that lives in the main process and offers a simple API.

const Store = require('electron-store');
const store = new Store();
store.set('user.name', 'Bob');
console.log(store.get('user.name'));
Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Electron.js Desktop App DevelopmentBrowse activities
Previous lessonBundling Renderer Code – Vite & WebpackContinue to lesson 11Data Persistence – electron-store, SQLite & LowDBBack to Electron.js Desktop App Development curriculum