Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda