This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
const useAutosave = (handleSave, debounceTimeout) => { | |
const [mounted, setMounted] = useState(false); | |
const [formValues, setFormValues] = useState({}); | |
const [lastSaved, setLastSaved] = useState({}); | |
const [submitting, setSubmitting] = useState(false); | |
useEffect(() => { | |
const timeout = setTimeout(async () => { | |
if (!mounted) return setMounted(true); |