Skip to content

Commit 8e5592c

Browse files
committed
Fix: Recents not being added issue
1 parent 862b7fa commit 8e5592c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

frontend/components/pages/ItemPage/ItemPage.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ export default function ItemPage() {
111111

112112
// setting recents of localstorage
113113
const recentArray = JSON.parse(localStorage.getItem("recents"));
114-
if (recentArray != null && !recentArray.includes(itemId)) {
114+
if (recentArray != null) {
115+
if (!recentArray.includes(itemId)) {
116+
localStorage.setItem(
117+
"recents",
118+
JSON.stringify([itemId, ...recentArray].slice(0, 20))
119+
);
120+
}
121+
} else {
115122
localStorage.setItem(
116123
"recents",
117-
JSON.stringify([itemId, ...recentArray].slice(0, 20))
124+
JSON.stringify([itemId])
118125
);
119126
}
120127
}, [itemId]);

0 commit comments

Comments
 (0)