liveBook · Manning

Cookie

As explained in React in Depth

A web cookie is a small piece of data that a website stores in a browser and can send with subsequent requests to a server.

A cookie persists small, browser-local settings while remaining available to both server and client. Because browsers send cookies with requests, server rendering can use the same preference that the client will use after hydration. section 11.3.3

Use cookies when a small value must survive visits and influence server-rendered output:

  • Store display preferences such as Celsius/Fahrenheit and 12-hour/24-hour time. section 11.3.3
  • Store a user's local city so the front page can find local weather. section 11.3.3
  • Prefer cookies over localStorage when the server must know the value before rendering; accept the smaller capacity because every request carries the data. section 11.3.3

Preventing a hydration mismatch

A weather route reads the temperature preference on the server, passes it into a format provider, and renders the same initial scale on the client. In Next.js, cookies-next reads values with getCookie, receiving request context on the server; Remix reads the Cookie header with parse() and writes changes with serialize().

How React in Depth covers it

How deep it goes
Explains request transmission, capacity trade-offs, hydration failure, and framework APIs, stopping short of broader cookie security policy.
Examples
Uses weather-scale, time-format, and local-city preferences, with Next.js and Remix route implementations.
What it assumes
Assumes React fundamentals and server/client rendering concepts while contrasting cookies with browser-only localStorage.
What you can do after
Apply it via cookies-next or Remix cookie utilities to synchronize small preferences between requests, server rendering, and clients.
How it connects
Connects cookies to localStorage, server-side rendering, hydration, Next.js, Remix, and progressive form submission.

Also explained in

Compare how 10 books explain cookie →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React in Depth. The section links point to the parts of the book it draws on.