cookies-next provides a compact client/server cookie API for Next.js. Cookies suit small preferences that must survive reloads and remain available during server rendering, though each request carries their data and storage is smaller than localStorage. section 11.3.3
Use the library with these implementation constraints:
- Read and write cookies in the browser from anywhere; server reads require the request context, while server writes require returning the appropriate response header. section 11.3.3
- Store small settings such as temperature scale and time format, rather than sizeable application data suited to localStorage. section 11.3.3
Reading format preferences in a server-rendered route
Import getCookie from cookies-next, read nextjs-isCelsius and nextjs-hour12 with getCookie(name, context), then normalize their string values into boolean defaults before rendering.
