diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts new file mode 100644 index 0000000..bc18d13 --- /dev/null +++ b/src/hooks/useLocalStorage.ts @@ -0,0 +1,18 @@ +import type { Accessor } from 'solid-js' +import { createSignal } from 'solid-js' + +export interface ILocalStorage { + lang: Accessor + setLang: (domain: string) => void +} + +const [lang, setLangeState] = createSignal((localStorage.getItem('LANG_KEY') as string) ?? 'com') + +const setLang: ILocalStorage['setLang'] = (domain) => { + localStorage.setItem('LANG_KEY', domain) + return setLangeState(domain) +} + +export const useLocalStorage = (): ILocalStorage => { + return { lang, setLang } +}