Fixed history repetition bug
This commit is contained in:
parent
2fab7d5193
commit
9eb6368b41
1 changed files with 8 additions and 1 deletions
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue