Skip to content

createChromeStorageStateHookLocal returns initial value first then the persisted one #469

Description

@Othmanosx

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions