electric-sql / electric-sql/electric
Feature request: customize localStorage implementation
- Dominant language
- TypeScript
- Stars
- 10.4k
- Forks
- 375
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 18
Description
**Is your feature request related to a problem? Please describe.**
Using ElectricSQL in React-Native leads to a poor user experience since the local cache gets thrown out when the user leaves the screen. This forces the app to refetch the same data all the time, and the user has to wait on a loading screen repeatedly.
**Describe the solution you'd like**
Adding a simple customization param for `localStorage` implementation could be a quick and easy fix until wrapper libraries like tanstack/db implement a proper persisted caching mechanism. This `localStorage` params could also be exposed as an option in the `electricCollectionOptions`. We can then pass a lib such as react-native-mmkv to it.
**Additional context**
Right now the [typescript-client](https://github.com/electric-sql/electric/tree/main/packages/typescript-client) simply skips localStorage when its not available: https://github.com/electric-sql/electric/blob/48c118a9724e8fb7f5b93da51948018568864436/packages/typescript-client/src/up-to-date-tracker.ts#L121 and https://github.com/electric-sql/electric/blob/48c118a9724e8fb7f5b93da51948018568864436/packages/typescript-client/src/expired-shapes-cache.ts#L40
Contributor guide
Assessment
This issue has not been assessed yet.