SolidJSS
SolidJS2y ago
35 replies
Dikiy

How to create a reactive localstorage?

Hi, I need to create a reactive localstorage for localization on my site but I don't know how to do it,
here is my attempt to make one:
const [locale, setLocale] = createStore({
        locale: "en",
    });
    const [localeJson, setLocaleJson] = createSignal(locales[locale.locale]);
    createEffect(() => {
        setLocaleJson(locales[locale.locale]);
    }, locale.locale);

but it doesn't work because when the page reloads, the value reverts to the original value
Was this page helpful?