Skip to content

Instantly share code, notes, and snippets.

View kristian240's full-sized avatar
🤯

Kristian Djaković kristian240

🤯
View GitHub Profile
import { Dispatch, SetStateAction, useCallback, useState } from 'react';
import { isServer } from '../utils/env';
export function useLocalStorage<T>(key: string, initialValue: T): [T, Dispatch<SetStateAction<T>>] {
const [value, _setValue] = useState<T>(() => {
if (isServer) {
return null;
}
const localValue = localStorage.getItem(key);