| import { useEffect, useState } from 'react'; |
| // export const useLocalStorage = <T>(key: string): T | null => { |
| // const [value, setValue] = useState<T | null>(null); |
| // if (typeof window !== 'undefined') { |
| // const item = localStorage.getItem(key); |
| // setValue(JSON.parse(item)); |
| // console.log(JSON.parse(item)); |
| // console.error(`解析 localStorage ${key} 失败`, e); |
| export const useLocalStorage = <T>(key: string): T | null => { |
| const isClient = typeof window !== 'undefined'; |
| const [value, setValue] = useState<T | null>(() => { |
| const item = localStorage.getItem(key); |
| console.error(`解析 localStorage ${key} 失败`, e); |
| const item = localStorage.getItem(key); |
| setValue(JSON.parse(item)); |
| console.error(`解析 localStorage ${key} 失败`, e); |