Skip to content

Instantly share code, notes, and snippets.

View DonnieTD's full-sized avatar
🏠
Working from home

Donovan van der Linde DonnieTD

🏠
Working from home
  • CTO @ WeavaCare
  • Cape Town
View GitHub Profile
@DonnieTD
DonnieTD / gist:fe928b1aadc4ecf01424e9ab46930e35
Created April 23, 2021 08:00
with Persist atom creator / with immer / with immer and persist
///////////////// CREATE ATOM THAT PERSISTS
import { atomWithReducer } from "jotai/utils";
import { WritableAtom } from "jotai/core/types";
type withpersistType = <T>(key: string, initial: T) => WritableAtom<T, T>;
const persis = (key: string, item: any) => {
localStorage.setItem(key, JSON.stringify(item));
return item;
};