To use Cookie, you can extract the cookie property and access its name and value directly.
There's no get/set, you can extract the cookie name and retrieve or update its value directly.
By default, Reactive Cookie can encode/decode type of object automatically. So if you like to set the cookie as an object, it will just work.
Teasim cookie is reactive, based on approach like signal.
Teasim cookie can sync the value of cookie, and set-headers automatically, providing a single source of truth for handling cookie.
If you don't set the new value for the cookie, the Set-Cookie
header will not be send to keep the same cookie value, so you don't have to worry about the performance.
By default, cookie is an object that rely on Proxy, so the extract value can never be undefined, it will always be a value of Cookie<unknown>
, which you can retrieve its value by calling .value property.
If you iterate over the cookie jar, the value will be only iterated over an existing cookie value, so you can treat it as a normal object.
To use Cookie attribute, you can either use one of the following:
set
or add
to update cookie property.See cookie attribute config for more information.
You can get/set the property of a cookie as if it's a normal object, the reactivity model will sync the cookie value automatically.
set allow us to set update multiple cookie property all at once, by reset all property and overwrite it with a new value.
Like set, add allow us to update multiple cookie property at once, but instead, will only overwrite the property defined instead of resetting.
To remove a cookie, you can either use:
You can strictly validate cookie type and providing type inference for cookie by using cookie schema with t.Cookie
.
To handle nullable cookie value, you can use t.Optional
on cookie name you want to be nullable.