Skip to content

Instantly share code, notes, and snippets.

View MuddyBootsCode's full-sized avatar

Michael Porter MuddyBootsCode

View GitHub Profile
import React, { Component, useState } from "react";
import "./App.css";
const useStateHistory = initialState => {
const [state, setState] = useState(initialState);
const [stateHistory, setStateHistory] = useState([state]);
const [historyIndex, setHistoryIndex] = useState(null);
const setStateWrapper = localState => {
if (historyIndex !== null) {
return setState(stateHistory[historyIndex]);