cookie-prefs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +17 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # cookie-prefs
2
2
 
3
- ![cookie-prefs: typed user preferences the server knows before the first render](.github/social-preview.png)
3
+ ![A preference is changed and saved as a cookie; after a reload the localStorage version jumps from the server's defaults while the cookie-prefs version is already right](.github/demo.gif)
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/cookie-prefs.svg)](https://www.npmjs.com/package/cookie-prefs)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/cookie-prefs.svg)](https://www.npmjs.com/package/cookie-prefs)
7
7
  [![CI](https://github.com/StanislavKozachenko/cookie-prefs/actions/workflows/ci.yml/badge.svg)](https://github.com/StanislavKozachenko/cookie-prefs/actions/workflows/ci.yml)
8
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
9
9
 
10
+ **[Live demo](https://cookie-prefs.vercel.app)**: the same dashboard on cookies and on `localStorage`, [side by side](https://cookie-prefs.vercel.app/compare). The side-by-side reload in the recording above is throttled (1.6 Mbps, 4x CPU slowdown) to keep the first paint on screen.
11
+
10
12
  Typed, cookie-backed user preferences for React and Next.js: theme, sidebar, density, locale, anything small. nuqs keeps state in the URL; cookie-prefs keeps it in cookies, so the server knows it before the first render.
11
13
 
12
14
  - Readable in Server Components and on the client, with no hydration flash.
@@ -16,6 +18,20 @@ Typed, cookie-backed user preferences for React and Next.js: theme, sidebar, den
16
18
  - The core has zero dependencies and fits a 2 kB gzip budget. `react` and `next` are optional peer dependencies.
17
19
  - `cookie-prefs/theme` is an API-compatible replacement for [next-themes](https://github.com/pacocoursey/next-themes) (its last release, 0.4.6, was in March 2025) that stores the choice in a cookie.
18
20
 
21
+ ## When to use what
22
+
23
+ | | `localStorage` | URL state ([nuqs](https://nuqs.dev)) | next-themes | cookie-prefs |
24
+ | ----------------------------------------- | --------------------------------- | ------------------------------------ | ------------------ | ----------------------------- |
25
+ | Meant for | client-only state | state worth sharing as a link | the theme | small per-user preferences |
26
+ | The server knows it before rendering | No | Yes | No | Yes |
27
+ | Server-rendered content matches on reload | No, corrected after hydration | Yes | Theme class only | Yes |
28
+ | Typed | By hand | Yes | Theme names | Yes |
29
+ | Synced across tabs | By hand (`storage` event) | No | Yes | Yes |
30
+ | Travels with a shared link | No | Yes | No | No |
31
+ | Sent with every request | No | Yes, in the URL | No | Yes, so keep it small |
32
+
33
+ They combine: filters and pagination belong in the URL, the theme and layout in cookies.
34
+
19
35
  ## Install
20
36
 
21
37
  ```sh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cookie-prefs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Typed cookie-backed user preference state for React and Next.js",
5
5
  "keywords": [
6
6
  "react",