x-state-manager
Version:
A lightweight state manager built on top of SWR for efficient state management with caching, optimistic updates, and modular architecture. It allows easy global and local state management, automatic data re-fetching on focus, and supports TypeScript
1 lines • 1.03 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import useSWRImmutable, {\n SWRConfiguration,\n SWRResponse,\n Key,\n mutate,\n} from 'swr';\n\ntype StateFetcher<T> = () => T | Promise<T>;\n\nconst mutateState = <T>(\n key: Key,\n data?: T,\n shouldRevalidate: boolean = false\n): Promise<T | undefined> => {\n return mutate<T>(key, data, shouldRevalidate);\n};\n\nfunction createSWRState<T>(\n key: Key,\n fetcher: StateFetcher<T> | null,\n config?: SWRConfiguration<T>\n): SWRResponse<T, any> {\n return useSWRImmutable<T>(key, fetcher, {\n revalidateIfStale: false,\n revalidateOnFocus: false,\n revalidateOnReconnect: false,\n ...config,\n });\n}\n\nexport { mutateState, createSWRState };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO;AAAA,EAIL;AAAA,OACK;AAIP,IAAM,cAAc,CAClB,KACA,MACA,mBAA4B,UACD;AAC3B,SAAO,OAAU,KAAK,MAAM,gBAAgB;AAC9C;AAEA,SAAS,eACP,KACA,SACA,QACqB;AACrB,SAAO,gBAAmB,KAAK,SAAS;AAAA,IACtC,mBAAmB;AAAA,IACnB,mBAAmB;AAAA,IACnB,uBAAuB;AAAA,KACpB,OACJ;AACH;","names":[]}