nuqs Library Brings Shareable, URL-Based State Management to Next.js Apps
nuqs is a library for Next.js that replaces component-level useState with URL query parameters, making UI state such as filters, search terms, and pagination persistent and shareable. It offers a useState-compatible API via a useQueryState hook, so developers can adopt it with minimal changes to existing code. The library supports typed parsers for integers, booleans, arrays, enums, and ISO dates, and allows multiple related parameters to be updated atomically through useQueryStates. Options like shallow: false ensure Server Components re-fetch when query parameters change, while history: push enables back-button navigation between filter states. nuqs is available via npm and integrates with the Next.js App Router through a dedicated adapter component.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in