React - make the cookie history last forever

0 votes
11 views
added Feb 5 in React by lcjr First Warrant Officer (10,930 points)

To make the cookie history last forever, you can set the expiration date of the cookie to a distant future date. You can achieve this by modifying the setCookie function call.

const handleDelete = (index) => {
  const updatedHistory = [...searchHistory];
  updatedHistory.splice(index, 1);
  setCookie('searchHistory', updatedHistory.reverse(), { path: '/', expires: new Date('2100-01-01') });
};

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...