feat(hooks): add useLocalStorage
This commit is contained in:
parent
40b9f29e03
commit
341f0fae65
18
src/hooks/useLocalStorage.ts
Normal file
18
src/hooks/useLocalStorage.ts
Normal 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 }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user