feat(hooks): add useLocalStorage

This commit is contained in:
Walid 2023-05-04 16:14:11 +01:00
parent 40b9f29e03
commit 341f0fae65
Signed by: Walidoux
GPG Key ID: CCF21881FE8BEBAF

View File

@ -0,0 +1,18 @@
import type { Accessor } from 'solid-js'
import { createSignal } from 'solid-js'
export interface ILocalStorage {
lang: Accessor<string>
setLang: (domain: string) => void
}
const [lang, setLangeState] = createSignal<string>((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 }
}