Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
How to presist a cookie with universal-cookie

I used this to set a cookie in my react application. It expires with hte session though. How can I store this cookie so it lasts beyond the session so it remains if the browser is closed and reopened?

export default function App() {

  const [classnameTr,setClassname] = useState<string>("checkbox-row1");
  const [classnameLabel, setClassnameLabel] = useState<string>("my-label-black"); 
  const cookies = new Cookies();

  function setCookie() {
    cookies.set('certDiscCookie', 'certDiscCookieSet', { path: '/' });
    console.log("Cookies: " + cookies.get('certDiscCookie'));
  }

  function getCookie() {
    if (cookies.get('certDiscCookie') === "certDiscCookieSet") {
      setColor();
    }
  }

  return (
    <div className="App">
      <header className="App-header">
        <div className="checkbox-div">
          <table className="checkbox-table">
            <tbody>
                <td className="tr2-td2"><button className="certDiscButtonSet" onClick={() => setCookie()}>Set Cookie</button></td>
                <td className="tr3-td3"><button className="certDiscButtonGet" onClick={() => getCookie()}>Get Cookie</button></td>
              </tr>
            </tbody>
          </table>
        </div>
      </header>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you don't set expires option it's gonna work similar to original cookies.set() option - it becomes session cookie. You have to set some time after which it expires. If you do that it will remain after you restart the browser. There is no way to make it live forever. You can just set the date far into the future.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda