{"library":"next-cookies","title":"Next Cookies","description":"Next Cookies is a focused utility library for Next.js applications, providing a straightforward method to read HTTP cookies on both the client and server sides. Currently at version 2.0.3, it offers a stable, minimalistic API centered around a single default export function that takes Next.js's `ctx` object (from `getInitialProps`) as an argument. Its primary differentiator is its simplicity and universal access pattern, allowing developers to consistently retrieve cookie values regardless of whether the page is rendered server-side or client-side. The package explicitly *does not* handle setting or deleting cookies, delegating these operations to native browser APIs like `document.cookie` or other specialized libraries. This clear separation of concerns makes it lightweight and easy to integrate for cookie *reading* tasks within the Next.js ecosystem. Given its mature state and narrow scope, it is likely in a maintenance cadence, receiving updates primarily for compatibility or critical bug fixes.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install next-cookies"],"cli":null},"imports":["import cookies from 'next-cookies'","const cookies = require('next-cookies')","import cookies from 'next-cookies'; import type { NextPageContext } from 'next';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import React from 'react';\nimport cookies from 'next-cookies';\n\nclass NameForm extends React.Component {\n  static async getInitialProps(ctx) {\n    return {\n      initialName: cookies(ctx).name || ''\n    };\n  }\n\n  constructor(props) {\n    super(props);\n    this.state = {name: props.initialName || ''};\n    this.handleChange = this.handleChange.bind(this);\n    this.reset = this.reset.bind(this);\n  }\n\n  handleChange(event) {\n    const newName = event.target.value;\n    this.setState({name: newName});\n    document.cookie = `name=${newName}; path=/`; // Set cookie directly via browser API\n  }\n\n  reset() {\n    this.setState({name: ''});\n    // Delete cookie directly via browser API by setting an past expiration date\n    document.cookie = 'name=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT';\n  }\n\n  render() {\n    return (\n      <div>\n        <p>Hi {this.state.name}</p>\n        <p>Change cookie: <input\n            type=\"text\"\n            placeholder=\"Your name here\"\n            value={this.state.name}\n            onChange={this.handleChange}\n          />!\n        </p>\n        <p>Delete cookie: <button onClick={this.reset}>Reset</button></p>\n      </div>\n    );\n  }\n}\n\nexport default NameForm;","lang":"typescript","description":"This example demonstrates how to read cookies using `next-cookies` within Next.js's `getInitialProps` and how to set/delete them using native browser `document.cookie` API.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}