Fixed history repetition bug

This commit is contained in:
Prozilla 2023-12-17 14:49:48 +01:00
parent 2fab7d5193
commit 9eb6368b41
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE

View file

@ -21,11 +21,18 @@ export function useHistory(initialState) {
if (state === history[0]) if (state === history[0])
return; return;
const newHistory = [ let newHistory = [
state, state,
...history.slice(stateIndex, history.length) ...history.slice(stateIndex, history.length)
]; ];
// Remove repeated states
newHistory = newHistory.filter((state, index) => {
return state !== newHistory[index + 1];
});
console.log(newHistory);
setHistory(newHistory); setHistory(newHistory);
setStateIndex(0); setStateIndex(0);
}; };