Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Game extends Compoent {
...
redo = () => {
const { history } = this.state;
let { historyOffSet } = this.state;
if (history.size) {
historyOffSet = Math.min(history.size - 1, historyOffSet + 1);
const board = history.get(historyOffSet);
this.setState({ board, historyOffSet });
}
};
undo = () => {
const { history } = this.state;
let { historyOffSet, board } = this.state;
if (history.size) {
historyOffSet = Math.max(0, historyOffSet - 1);
board = history.get(historyOffSet);
this.setState({ board, historyOffSet, history });
}
};
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.