Used to set up action forwarding in the Electron renderer process. Middleware must be added to both processes to ensure communication works.

import { createRedialRendererMiddleware } from "@laserware/redial/renderer";
import { configureStore, type Store } from "@reduxjs/toolkit";

import { rootReducer } from "../common/rootReducer";

export function createStore(): Store {
const redialMiddleware = createRedialRendererMiddleware();

let preloadedState;
// If using Vite:
if (import.meta.env.MODE === "development") {
preloadedState = redialMiddleware.getMainStateSync();
}

const store = configureStore({
preloadedState,
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(redialMiddleware),
});
}

Interfaces

RedialRendererMiddleware

Redial middleware in the renderer process. Provides a dispose method to clean up resources as well as methods to get the state from the main process asynchronously or synchronously.

Functions

createRedialRendererMiddleware

Whenever an action is fired from the renderer process, forward it to the main process to ensure global state is in sync. The optional hooks argument allows you to make changes to the action prior to forwarding it to the main process and after forwarding to the main process before passing the action to the next middlewares.