Skip to content

Commit 7822608

Browse files
overwrite users instead of appending them to the existing object
1 parent 2936a95 commit 7822608

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/api/fetchUsers.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ const fetchUsers = async (
2424
throw new Error('Received data was not ok')
2525
}
2626

27-
setUsers((prev) => {
28-
const merged = [...prev, ...data]
29-
const unique = Array.from(
30-
new Map(merged.map((item) => [item.id, item])).values()
31-
)
32-
33-
setItemInSessionStorage('users', unique)
34-
35-
return unique
27+
setUsers(() => {
28+
setItemInSessionStorage('users', data)
29+
return data
3630
})
3731
} catch (error: unknown) {
3832
console.error('An error occurred while fetching the users.', error)

0 commit comments

Comments
 (0)