@@ -55,8 +55,24 @@ export type UseCookieInitialValue<Value> = (() => Value) | Value;
5555
5656/* The use storage options type */
5757export interface UseCookieOptions < Value > {
58+ /* The domain of the cookie */
59+ domain ?: string ;
60+ /* The expiration date of the cookie */
61+ expires ?: Date ;
62+ /* Whether the cookie is httpOnly */
63+ httpOnly ?: boolean ;
5864 /* The initial value of the storage */
5965 initialValue ?: UseCookieInitialValue < Value > ;
66+ /* The maximum age of the cookie */
67+ maxAge ?: number ;
68+ /* The path of the cookie */
69+ path ?: string ;
70+ /* The sameSite of the cookie */
71+ sameSite ?: 'Lax' | 'None' | 'Strict' ;
72+ /* Whether the cookie is secure */
73+ secure ?: boolean ;
74+ /* Whether to update the cookie on change */
75+ updateOnChange ?: boolean ;
6076 /* The deserializer function to be invoked */
6177 deserializer ?: ( value : string ) => Value ;
6278 /* The serializer function to be invoked */
@@ -144,7 +160,7 @@ export const useCookie = <Value>(
144160 const cookieValue = getCookieItem ( key ) ;
145161 if ( cookieValue === undefined && initialValue !== undefined ) {
146162 const value = initialValue instanceof Function ? initialValue ( ) : initialValue ;
147- setCookieItem ( key , serializer ( value ) ) ;
163+ setCookieItem ( key , serializer ( value ) , options ) ;
148164 return value ;
149165 }
150166 return cookieValue ? deserializer ( cookieValue ) : undefined ;
@@ -159,9 +175,9 @@ export const useCookie = <Value>(
159175 return ( ) => window . removeEventListener ( COOKIE_EVENT , onChange ) ;
160176 } , [ key ] ) ;
161177
162- const set = ( value : Value , options ?: SetCookieParams ) =>
163- setCookieItem ( key , serializer ( value ) , options ) ;
164- const remove = ( options ?: RemoveCookieParams ) => removeCookieItem ( key , options ) ;
178+ const set = ( value : Value , params ?: SetCookieParams ) =>
179+ setCookieItem ( key , serializer ( value ) , { ... options , ... params } ) ;
180+ const remove = ( params ?: RemoveCookieParams ) => removeCookieItem ( key , { ... options , ... params } ) ;
165181
166182 return { value, set, remove } ;
167183} ;
0 commit comments