useLocalStorage
로컬스토리지를 효율적으로 사용할 수 있는 훅스입니다.
Copy Code
hooks/use-localstorage.tsx
'use client'
function useLocalStorage(key: 'item1' | 'item2') {
const item = window.localStorage.getItem(key)
const setItem = (value: string) => window.localStorage.setItem(key, value)
return [item, setItem]
}
export default useLocalStorage
Usage
const [item, setItem] = useLocalStorage('item1')