Skip to content

Commit

Permalink
Set Correct Initial Data for Difference Calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NPJigaK committed Oct 21, 2023
1 parent b8837ef commit ecf8ef4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/accessTwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,16 @@ export const useNowAllFollowers = () => {
const resJson = await res.json();
const followers = await fetchFollowers(resJson.data[0].id);

if (!localStorage.getItem(storedAllFollowersKey)) {
// addedUsers の差分が全てのユーザーにならないように、初期値はfollowers
localStorage.setItem(storedAllFollowersKey, JSON.stringify(followers));
}

const result = await findDifference(
followers,
JSON.parse(localStorage.getItem(storedAllFollowersKey) ?? "[]")
JSON.parse(localStorage.getItem(storedAllFollowersKey) as string)
);

debugLogger(result.removedUsers);
debugLogger(result.addedUsers);
setNowAllFollowers(followers);
Expand Down

0 comments on commit ecf8ef4

Please sign in to comment.