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

167
Views
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 answers
Answer question

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 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!