guys, I’ve just made Cookies utility that compatible in Server Components, Client Components, and Server Actions 👀🔥

it just works with all Context in NextJS 13 appDir without problems🔥

Content Image Content Image Content Image

first, we made an abstraction so that the Cookie utility between Server and Client has the same API.

Content Image

then we create 2 different utilities between Server and Client with the BaseCookie blueprint that was created before.

in Cookie.server, it uses the default cookies utility from next/headers that only works on Server here is reference

in Cookie.client, we use js-cookie.

Content Image Content Image

finally, the function that can bridge between Cookie.server and Cookie.client 🔥

Content Image
  • but, why use require()? why not import statement? I don’t know, when i use import statement, i get error like this.

  • why not dynamic import? Man, I want to use Cookies just synchronously without thinking about Promises 🤯

so, that is 🚀

Content Image

this is auto generated content from ThreadsApp. see original at @gadingnst

Share