Lesson 10 of 28
javascriptState Management Across Processes
10 mins
Course progress36%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 10 of 28
javascript10 mins
Keep these ideas in mind as you work through the lesson.
Because the UI lives in a separate renderer, you need a strategy to keep data in sync.
getState / setState via the preload bridge.// 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))
});
const Store = require('electron-store');
const store = new Store();
store.set('user.name', 'Bob');
console.log(store.get('user.name'));