Skip to content

Instantly share code, notes, and snippets.

View highlander08's full-sized avatar
:octocat:
Codar por Paixão | Aluno | @Rocketseat

Highlander Santos highlander08

:octocat:
Codar por Paixão | Aluno | @Rocketseat
View GitHub Profile
@fedek6
fedek6 / useLocalStorage.ts
Created August 2, 2021 20:32
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));
};
@jimode
jimode / context-and-localstorage-using-hooks.js
Last active January 1, 2024 06:13
Providing Context and Local Storage Using Hooks
// Providing Context
// ==================
import React, {useState, useEffect} from "react"
const Context = React.createContext()
function ContextProvider({children}) {
const [allPhotos, setAllPhotos] = useState([])
const [cartItems, setCartItems] = useState([])