From 9eb6368b41941fd803a4d13a23be1fe101f8486f Mon Sep 17 00:00:00 2001 From: Prozilla Date: Sun, 17 Dec 2023 14:49:48 +0100 Subject: [PATCH] Fixed history repetition bug --- src/hooks/utils/history.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hooks/utils/history.js b/src/hooks/utils/history.js index 5841906..9153655 100644 --- a/src/hooks/utils/history.js +++ b/src/hooks/utils/history.js @@ -21,11 +21,18 @@ export function useHistory(initialState) { if (state === history[0]) return; - const newHistory = [ + let newHistory = [ state, ...history.slice(stateIndex, history.length) ]; + // Remove repeated states + newHistory = newHistory.filter((state, index) => { + return state !== newHistory[index + 1]; + }); + + console.log(newHistory); + setHistory(newHistory); setStateIndex(0); };