Skip to content

Conversation

@abhichaurasiya2022
Copy link

Overview

This PR adds a new hook called useCookieStorage to enable React state synchronization with browser cookies.

Features

  • Reading/Writing JSON Values: Automatically serializes and deserializes values as JSON
  • Type-Safe CookieOptions: Supports configurable cookie options including:
    • expires: Number of days from now or a Date object (default: 365 days)
    • path: Cookie path (default: '/')
    • sameSite: SameSite attribute ('Lax', 'Strict', or 'None', default: 'Lax')
    • secure: Secure flag for HTTPS-only cookies (default: false)
  • Initial Default Value: Allows setting an initial value when the cookie doesn't exist
  • Automatic Reactivity: Uses useSyncExternalStore for cross-tab updates, ensuring state synchronization across browser tabs

Related Issue

Resolves #272

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant