Smarter Cookie Management, Seamless Sync
npm install create-cookieEffortless Cookie Management for React
Easily get, set, and sync cookies across components with a simple API.




- 🍪 Simplified Cookie Handling – Manage cookies without manually dealing with document.cookie.
- 🔄 Real-time Updates – React to cookie changes instantly.
- ⚡ Lightweight & Dependency-Free – Minimal impact on your bundle size.
- 🛠 Easy API – Get, set, reset, and check cookies effortlessly.
- 📡 Automatic Expiry Handling – Set expiration dates and paths with ease.
Install via your preferred package manager:
``shnpm
npm install create-cookie
🔍 Basic Usage
`tsx
"use client";import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const theme = createCookie("theme", "light");
return (
Theme: {theme.get()}
);
};export default Page;
`🔍 API Reference
$3
A React hook for reading and updating cookies easily.
#### Parameters
-
key (string): The key under which the value is stored in cookies.
- initialValue (T, optional): The initial value to set if the key does not exist.
- options (CookieOptions, optional): Additional settings like expires and path.#### Returns
- An object with the following methods:
-
get(): Retrieve the current cookie value.
- set(value: T, options?: CookieOptions): Update the cookie value.
- reset(): Clear the cookie.
- hasValue(): Check if the cookie exists.💡 Examples
$3
`tsx
"use client";import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const language = createCookie("language", "en");
return (
Language: {language.get()}
);
};export default Page;
`$3
`tsx
"use client";import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const sessionToken = createCookie("session", "", { expires: 7 });
return (
Session Token: {sessionToken.get()}
);
};export default Page;
`🔒 Security & Provenance
This package is published with NPM package provenance, which provides supply chain security by cryptographically linking the published package to its source code and build process.
$3
You can verify that this package was built from the source code in this repository:
`bash
Install the package
npm install create-cookieVerify the provenance
npm audit signaturesOr use the provided verification script
npm run verify-provenance
``- Supply Chain Security: Prevents malicious package injection
- Trust: Verify package authenticity and origin
- Transparency: Links packages to source code and build process
- Compliance: Meets security requirements for many organizations
For more information about NPM package provenance, see the official documentation.
Contributions are welcome! To contribute:
1. Fork the repository.
2. Create a feature branch.
3. Commit your changes.
4. Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
---
This package is developed and maintained by JP.Coffee. Feel free to reach out or open an issue for any questions or suggestions!