React - make the cookie history last forever

0 votes
379 views
added Feb 5, 2024 in React by lcjr Lieutenant (12,520 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.
...