Skip to content

Bounds Persistence

Add persistBounds with a unique key. Bounds save automatically to localStorage and restore on next open.

<Window
open={show}
persistBounds="settings"
defaultWidth={600}
defaultHeight={400}
>
<Settings />
</Window>

First open uses the defaults. After the user resizes or moves the window, those bounds are saved. Next open restores them.

The key should be unique per window. Use something stable and descriptive like "settings" or "editor-main".

For cases where you need to read bounds before rendering, reset them programmatically, or integrate with your own storage:

import { usePersistedBounds } from "@loc/electron-window";
function PersistentWindow({ children }) {
const { bounds, save, clear } = usePersistedBounds("my-window", {
defaultWidth: 800,
defaultHeight: 600,
});
return (
<Window open {...bounds} onBoundsChange={save}>
{children}
<button onClick={clear}>Reset Position</button>
</Window>
);
}
OptionTypeDefaultDescription
defaultWidthnumberWidth when nothing is saved
defaultHeightnumberHeight when nothing is saved
defaultXnumberX position when nothing is saved
defaultYnumberY position when nothing is saved
saveDebounceMsnumber500Debounce for save() — writes coalesce
ValueTypeDescription
bounds{ defaultWidth?, defaultHeight?, defaultX?, defaultY? }Saved bounds mapped to default* prop names, or the defaults you passed. Spread directly into <Window {...bounds}>.
save(bounds: Bounds) => voidPersist new bounds (pass directly to onBoundsChange). Debounced.
clear() => voidRemove saved bounds, revert to defaults

The bounds keys are defaultWidth/defaultHeight/defaultX/defaultY — not width/height/x/y — so spreading them doesn’t accidentally create a controlled window.

For “reset all settings” or logout flows where you don’t have the hook mounted:

import { clearPersistedBounds, clearAllPersistedBounds } from "@loc/electron-window";
clearPersistedBounds("settings"); // one key
clearAllPersistedBounds(); // every key this library has stored

Bounds are stored in localStorage under a namespaced key (electron-window:bounds:<your-key>). The stored value includes x, y, width, and height.