From ecf8ef4381b5ab4cce5572df21054703991a04c7 Mon Sep 17 00:00:00 2001 From: NPJigaK Date: Sun, 22 Oct 2023 04:50:54 +0900 Subject: [PATCH] Set Correct Initial Data for Difference Calculation --- lib/accessTwitch.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/accessTwitch.ts b/lib/accessTwitch.ts index 62b25c8..eddb59a 100644 --- a/lib/accessTwitch.ts +++ b/lib/accessTwitch.ts @@ -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);