🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

react-cookie

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cookie

Universal cookies for React

8.0.1
latest
Source
npm
Version published
Weekly downloads
614K
1.51%
Maintainers
1
Weekly downloads
 
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

universal

FAQs

Package last updated on 18 Mar 2025

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