
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
create-cookie
Advanced tools
Effortless Cookie Management for React Easily get, set, and sync cookies across components with a simple API.
document.cookie
.Install via your preferred package manager:
# npm
npm install create-cookie
# yarn
yarn add create-cookie
# pnpm
pnpm add create-cookie
# bun
bun add create-cookie
"use client";
import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const theme = createCookie("theme", "light");
return (
<div>
<h1>Theme: {theme.get()}</h1>
<button onClick={() => theme.set("dark")}>Set Dark Theme</button>
<button onClick={() => theme.reset()}>Reset Theme</button>
</div>
);
};
export default Page;
createCookie<T>(key: string, initialValue?: T, options?: CookieOptions)
A React hook for reading and updating cookies easily.
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
.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."use client";
import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const language = createCookie("language", "en");
return (
<div>
<h1>Language: {language.get()}</h1>
<button onClick={() => language.set("fr")}>Set to French</button>
</div>
);
};
export default Page;
"use client";
import { createCookie } from "create-cookie";
const Page: React.FC = () => {
const sessionToken = createCookie("session", "", { expires: 7 });
return (
<div>
<h1>Session Token: {sessionToken.get()}</h1>
<button onClick={() => sessionToken.set("abc123", { expires: 7 })}>
Set Token (Expires in 7 days)
</button>
</div>
);
};
export default Page;
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.
You can verify that this package was built from the source code in this repository:
# Install the package
npm install create-cookie
# Verify the provenance
npm audit signatures
# Or use the provided verification script
npm run verify-provenance
For more information about NPM package provenance, see the official documentation.
Contributions are welcome! To contribute:
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!
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.