Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cookie

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cookie

Universal cookies for React

  • 7.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is react-cookie?

The react-cookie package is a library for handling cookies in React applications. It provides hooks and components to easily set, get, and remove cookies, making it simple to manage user sessions and preferences.

What are react-cookie's main functionalities?

Setting a Cookie

This feature allows you to set a cookie using the `useCookies` hook. In this example, a cookie named 'user' is set with the value 'John Doe' when the login button is clicked.

import { useCookies } from 'react-cookie';

function App() {
  const [cookies, setCookie] = useCookies(['user']);

  const handleLogin = () => {
    setCookie('user', 'John Doe', { path: '/' });
  };

  return (
    <div>
      <button onClick={handleLogin}>Login</button>
    </div>
  );
}

Getting a Cookie

This feature allows you to get a cookie using the `useCookies` hook. In this example, the value of the 'user' cookie is displayed in a paragraph.

import { useCookies } from 'react-cookie';

function App() {
  const [cookies] = useCookies(['user']);

  return (
    <div>
      <p>User: {cookies.user}</p>
    </div>
  );
}

Removing a Cookie

This feature allows you to remove a cookie using the `useCookies` hook. In this example, the 'user' cookie is removed when the logout button is clicked.

import { useCookies } from 'react-cookie';

function App() {
  const [cookies, setCookie, removeCookie] = useCookies(['user']);

  const handleLogout = () => {
    removeCookie('user', { path: '/' });
  };

  return (
    <div>
      <button onClick={handleLogout}>Logout</button>
    </div>
  );
}

Other packages similar to react-cookie

Keywords

FAQs

Package last updated on 29 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc