I've been using createChromeStorageStateHookLocal for some time now for my Chrome extension but I noticed an annoying rerender issue that I couldn't debug, for some reason, the hook always returns the initial values on the first render then rerenders again with the persisted values.
The expected behavior:
on the first render, the hook should return the persisted values if they exist and fallback to the initial values, and should not render twice.
How I'm using it right now:
const SETTINGS_KEY = 'settings';
const INITIAL_VALUE: Settings = {
isDark: false,
};
export const useSettingsStore = createChromeStorageStateHookLocal(SETTINGS_KEY, INITIAL_VALUE);
const [{ isDark }] = useSettingsStore()
// assuming that the persisted value of isDark is "true"
console.log(isDark) // 1st render: false, 2nd render: true
I've been using
createChromeStorageStateHookLocalfor some time now for my Chrome extension but I noticed an annoying rerender issue that I couldn't debug, for some reason, the hook always returns the initial values on the first render then rerenders again with the persisted values.The expected behavior:
on the first render, the hook should return the persisted values if they exist and fallback to the initial values, and should not render twice.
How I'm using it right now: