← Back to libraryAdd features
Add data persistence
Data vanishes on refresh - make it stick
The prompt
My data lives in memory or local state right now and disappears on refresh. I need persistence. Current state: {{where data lives now, e.g. React state / localStorage}} Data to store: {{the shape}} Scenario: {{single user / multi-user / needs cross-device sync?}} Stack: {{e.g. Next.js}} Please: 1. Recommend a storage option for my scenario (localStorage / file / SQLite / hosted DB) with tradeoffs. 2. Give complete integration code including reads, writes and error handling. 3. Cover migration: what happens to data that already exists? 4. Flag what to watch: concurrent writes, validation, backups, privacy. Rules: - Do not jump to the most complex option - localStorage may genuinely be enough here. - For user data, call out privacy and compliance explicitly. - Give me a way to verify the data is actually persisted.
Replace the {{}} parts with your own content
Why it works
- Scenario-based recommendation instead of defaulting to a database avoids over-engineering - many small tools are fine with localStorage
- "What about migration" is the most forgotten and most painful step when adding persistence
- Requiring privacy and compliance notes matters because these are hard constraints once real users are involved
- A verification method confirms data truly landed instead of assuming it did
What it looks like
For a local tool, AI may suggest starting with localStorage (zero cost) and say at what scale moving to a real database becomes worth it.
Where it bites
- Reaching for a database immediately and taking on ops burden for a single-user tool
- Skipping validation, so data writes fine and reads back dirty