Skip to content

Instantly share code, notes, and snippets.

View Aissa-Bedr's full-sized avatar

Aissa Bedr Aissa-Bedr

View GitHub Profile
@Aissa-Bedr
Aissa-Bedr / useLocalStorage.ts
Created January 4, 2023 18:07 — forked from fedek6/useLocalStorage.ts
Working useLocalStorage hook for Next.js (no warnings in console)
/* eslint-disable no-console */
/* eslint-disable react-hooks/exhaustive-deps */
import { useState, useEffect } from "react";
export const useLocalStorage = <T>(key: string, initialValue: T) => {
const [storedValue, setStoredValue] = useState<T | undefined>();
const setValue = (value: T) => {
window.localStorage.setItem(key, JSON.stringify(value));
};