Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
How to remove a cookie from a browser in react?

I am trying to remove the token cookie from the browser when logging out but with my current code that doesn't seem to be working. Also the Cookie.get() function is returning an empty object when a cookie is still visible in the browser. I have tried looking at other solutions but nothing seem to be working.

import { useNavigate } from "react-router-dom";
import history from "../../history";
import Cookie from "js-cookie";

export default function Tool() {
  const navigate = useNavigate();

  function logout() {
    localStorage.clear();
    Cookie.remove("token");
    console.log(Cookie.get(), "Oooooooooooooo");
    navigate("/login");
  }

  return (
    <div >
      <div className="topButtons">
        <button onClick={() => logout()}>LogOut</button>
      </div>
    </div>
  );
}
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try remove all cookies first: document.cookie = ''

about 4 years ago · Santiago Trujillo Report

0

Using the remove method from library

Cookies.remove('name')
// Removing a nonexistent cookie neither raises any exception nor returns any value.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!