React - make the cookie history last forever

0 votes
added Feb 5 in React by lcjr First Warrant Officer (11,970 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') });
}; - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.