Skip to content

Instantly share code, notes, and snippets.

View JohanAltamar's full-sized avatar
🎯
Focusing

Johan Altamar JohanAltamar

🎯
Focusing
View GitHub Profile
@JohanAltamar
JohanAltamar / usePersistedState.jsx
Last active September 22, 2020 04:50
Persist react hooks state at LocalStorage
import { useEffect, useState } from 'react';
export function usePersistedState(key, defaultValue) {
const [state, setState] = useState(
() => JSON.parse(localStorage.getItem(key)) || defaultValue
);
useEffect(() => {
localStorage.setItem(key, JSON.stringify(state));
}, [key, state]);
return [state, setState];
@JohanAltamar
JohanAltamar / Carousel.css
Created August 21, 2020 17:41
Carousel component to use inside your React, Gatsby projects. An example can be found on https://johanaltamar.com/portfolio/delivree